Selenium,Remote调用:
参考文档:https://www.jianshu.com/p/2ee251c81c1f
一、环境配置
- Selenium浏览器驱动
- 下载 selenium-server-standalone
- 启动:
java -jar selenium-server-standalone-3.141.59.jar -port 4446 # 默认 4444
- JDK环境
- 官网下载安装:https://www.oracle.com/java/technologies/javase-jdk8-downloads.html
- 检测环境:
java -version
- 配置环境变量
- 查看
java_home
路径:/usr/libexec/java_home
- 添加配置信息:
vi ~/.profile
- 查看
JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_181.jdk/Contents/Home
CLASSPAHT=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
PATH=$JAVA_HOME/bin:$PATH:
export JAVA_HOME
export CLASSPATH
export PATH
- 确认配置是否成功:
echo $JAVA_HOME
二、脚本测试Demo
# -*- coding:utf-8 -*-
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from threading import Thread
import time
def open_web(remote_name, remote_address, web_url):
print('---- 启动: %s' % (remote_name))
driver = webdriver.Remote(command_executor=remote_address, desired_capabilities=DesiredCapabilities.CHROME)
driver.get(web_url)
# 关闭浏览器
time.sleep(5)
driver.quit()
if __name__ == "__main__":
data = {
# 'linux': '',
# 'windows': '',
'localhost': 'http://localhost:4444/wd/hub'
}
web_url = 'https://baidu.com/'
for name, address in data.items():
print('---- name:{} address:{}'.format(name, address))
# print('---- name:%s address:%s' % (name, address))
# 多线程
t = Thread(target=open_web, args=(name, address, web_url))
t.start()
# t.join()
三、终端检验接口是否联通
-
检验网站或IP是否连通:
ping www.baidu.com
ping localhost
ping http://localhost:4444/wd/hub
ping 10.32.128.139
-
检验端口是否连通:
telnet 10.32.128.139 5328
网友评论