1.hub和node服务一定要同时开启,及时你的脚本只在hub节点上运行;
hub默认端口号为4444,node默认端口号为5555。
java -jar selenium-server-standalone-3.141.59.jar -role hub
java -jar selenium-server-standalone-3.141.59.jar -role node
2.检查firefox的浏览器驱动器geckodriver.exe(放在python的安装目录下)的版本是否跟firefox的版本一致。我之前为了使用firebug和firepath插件,安装了低版本的firefox,geckodriver.exe也是低版本的。后来升级了firefox,忘记更换geckodriver.exe了。
firefox浏览器驱动下载
https://github.com/mozilla/geckodriver/releases/

这是geckodriver.exe v0.24.0的说明,需要firefox是版本65以上的,我的firefox版本是68.0.1,用geckodriver.exe v0.24.0可以正常运行。
除了firefox,其它浏览器也可能会出现
“ConnectionRefusedError: [WinError 10061] 由于目标计算机积极拒绝,无法连接。”

网上自己搜索了下解决方法,要修改代理为自动检测,实际没有勾选,重启Selenium Server,再次执行就没有报错了……
from selenium.webdriver import Remote
#定义主机与浏览器
lists={'http://127.0.0.1:4444/wd/hub':'internet explorer','http://127.0.0.1:5555/wd/hub':'chrome','http://127.0.0.1:5556/wd/hub':'firefox'}
#通过不同的浏览器执行脚本
for host,browser in lists.items():
print(host,browser)
#调用Remote方法
driver=Remote(command_executor=host,desired_capabilities={'platform':'ANY','browserName':browser,'version':'','javascriptEnabled':True})
driver.get('https://www.baidu.com/')
driver.find_element_by_id("kw").send_keys("remote")
driver.find_element_by_id("su").click()
driver.quit()
本文介绍了在使用Selenium Server启动Firefox时遇到的错误,强调了hub和node服务的同步开启,以及Firefox版本与geckodriver版本匹配的重要性。同时提到了其他浏览器可能遇到的"ConnectionRefusedError",并给出了解决方法,包括修改代理设置。最后提供了一个通过Remote方法执行不同浏览器脚本的示例。
3008

被折叠的 条评论
为什么被折叠?



