我正在尝试与Selenium启动远程Firefox会话。这是代码:
def Mozilla():
from selenium.webdriver.firefox.options import Options as Options_Mozilla
sys.path.append("/opt/app/venv/bin")
ff_options = Options_Mozilla()
ff_options.add_argument("--headless")
ff_options.set_preference("network.proxy.type", 1)
ff_options.set_preference("network.proxy.http", "some_address")
ff_options.set_preference("network.proxy.http_port", 8080)
ff_options.set_preference("network.proxy.ssl", "some_address")
ff_options.set_preference("network.proxy.ssl_port", 8080)
#profile.update_preferences()
#builtins.browser = webdriver.Firefox(firefox_profile=profile, firefox_options=ff_options)
#builtins.browser = webdriver.Firefox(firefox_options=ff_options)
builtins.browser = webdriver.Remote(command_executor="http://some_other_address/wd/hub", desired_capabilities=ff_options.to_capabilities())
执行代码后,我得到:
Traceback (most recent call last):
File "Creditview_PL.py", line 15, in <module>
DS.Mozilla()
File "/home/ad.ing.net/ji34ix/Projects/DS/DziadowskieSelenium.py", line 35, in Mozilla
builtins.browser = webdriver.Remote(command_executor="http://172.22.164.33:4444/wd/hub", desired_capabilities=ff_options.to_capabilities())
File "/opt/app/venv/lib64/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 156, in __init__
self.start_session(capabilities, browser_profile)
File "/opt/app/venv/lib64/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 251, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "/opt/app/venv/lib64/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 320, in execute
self.error_handler.check_response(response)
File "/opt/app/venv/lib64/python3.6/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: The path to the driver executable must be set by the webdriver.gecko.driver system property; for more information, see https://github.com/jgraham/wires. The latest version can be downloaded from https://github.com/jgraham/wires
令我惊讶的是,当我使用此代码(没有远程驱动程序)时:
def Mozilla():
from selenium.webdriver.firefox.options import Options as Options_Mozilla
sys.path.append("/opt/app/venv/bin")
ff_options = Options_Mozilla()
ff_options.add_argument("--headless")
ff_options.set_preference("network.proxy.type", 1)
ff_options.set_preference("network.proxy.http", "some_address")
ff_options.set_preference("network.proxy.http_port", 8080)
ff_options.set_preference("network.proxy.ssl", "some_address")
ff_options.set_preference("network.proxy.ssl_port", 8080)
builtins.browser = webdriver.Firefox(firefox_options=ff_options)
一切正常!完全没有找到壁虎驱动程序的问题。
我还确认带有geckodriver的文件夹在“路径”中。必须如此,否则第二个代码将无法工作。互联网的常识建议设置webdriver.gecko.driver系统属性,但示例代码看起来不像Python。如您所见,我使用了sys.path.append,但是它根本没有帮助。
Some versions:
Mozilla Firefox 60.1.0
geckodriver 0.21.0
selenium==3.13.0
网格节点的配置:
java -jar /opt/Selenium_grid/selenium-server-standalone-2.49.1.jar -role node -port 5555 -maxInstances=10 -Dwebdriver="opt/app/venv/bin" &> nodelog1.txt &
所以,有人可以帮我弄清楚为什么远程驱动程序找不到geckodriver吗?
答案 0 :(得分:0)
令我惊讶的是,当我使用此代码(没有远程驱动程序)时:一切 工程!完全没有找到壁虎驱动程序的问题。我也确认 带有geckodriver的文件夹位于“路径”中。必须如此,否则 第二个代码将无法工作。
您正在比较两种不同的执行模式。第二个变种基本上是尝试从开始运行python测试用例的同一台机器上打开firefox浏览器。
第一个变体基本上是试图在远程计算机上打开firefox浏览器(这里我假设您的网格在另一台计算机上运行)。因此,这里发生的事情是Selenium基本上告诉您它无法在远程计算机(具体来说是Selenium节点)中找到geckodriver。
要解决此问题,您有两种选择:
PATH
变量中,杀死硒节点,关闭终端并打开一个新终端(以便重新读取PATH
) ,然后重新启动节点。java -Dwebdriver.gecko.driver=opt/app/venv/bin -jar /opt/Selenium_grid/selenium-server-standalone-2.49.1.jar -role node -port 5555 -maxInstances=10 &> nodelog1.txt &
PS:您正在硒网格一侧使用非常老版本的Selenium(2.49.1)。请考虑升级到最新版本(截至今天为3.14.0)