Selenium远程驱动程序无法找到geckodriver

问题描述 投票:0回答:1

我正在尝试使用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的问题。

我还确认带有geckodriver的文件夹在Path中。它必须是,否则第二个代码将无法工作。常见的互联网知识建议设置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?

python-3.x selenium-webdriver selenium-grid geckodriver
1个回答
0
投票

令我惊讶的是,当我使用这段代码(没有远程驱动程序)时:一切正常!完全没有找到geckodriver的问题。我还确认带有geckodriver的文件夹在Path中。它必须是,否则第二个代码将无法工作。

您正在比较两种不同的执行模式。第二个变体基本上尝试在python测试用例开始运行的同一台机器上打开一个firefox浏览器。

第一个变体基本上是尝试在远程机器中打开firefox浏览器(这里我假设您的网格在另一台机器上运行)。所以这里发生的事情是Selenium基本上告诉你它无法在远程机器中找到geckodriver(特定的selenium节点)。

要解决此问题,您有两种选择:

  1. 将geckodriver二进制文件的位置添加到远程selenium节点上的PATH变量,杀死你的selenium节点,关闭终端并打开一个新的(以便新读取PATH),然后重新启动你的节点。
  2. 在node start命令的开头添加JVM参数。像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)

© www.soinside.com 2019 - 2024. All rights reserved.