简体   繁体   English

无法使用Python和geckodriver在Raspbian下运行selenium-webdriver

[英]Cannot get selenium-webdriver running under Raspbian using Python and geckodriver

I am trying to get selenium running in headless mode on a raspberry pi. 我试图让硒在树莓派上以无头模式运行。 My scripts work perfectly fine on my Windows machine, but I just cannot get this particular combination working: 我的脚本在Windows机器上可以正常运行,但是我无法使这种特殊组合正常工作:

  • Raspbian GNU/Linux 9 (stretch) Raspbian GNU / Linux 9(拉伸)
  • Python 3.7.3 的Python 3.7.3
  • geckodriver 0.23.0 ( 2018-10-04) 壁虎驱动程序0.23.0(2018-10-04)
  • selenium-server-standalone-3.141.59 selenium-server-standalone-3.141.59
  • Mozilla Firefox 52.9.0 Mozilla Firefox 52.9.0

first I launch selenium-server-standalone as described in the documentation : 首先,我按照文档中所述启动selenium-server-standalone

$ java -jar selenium-server-standalone-3.141.59.jar &
[1] 1842
14:39:26.881 INFO [GridLauncherV3.parse] - Selenium server version: 3.141.59, revision: e82be7d358
14:39:27.321 INFO [GridLauncherV3.lambda$buildLaunchers$3] - Launching a standalone Selenium Server on port 4444
2019-06-30 14:39:27.589:INFO::main: Logging initialized @2114ms to org.seleniumhq.jetty9.util.log.StdErrLog
14:39:28.755 INFO [WebDriverServlet.<init>] - Initialising WebDriverServlet
14:39:29.174 INFO [SeleniumServer.boot] - Selenium Server is up and running on port 4444

Then I run following test script in Python: 然后,我在Python中运行以下测试脚本:

from selenium import webdriver
from selenium.webdriver.firefox.options import Options
from pyvirtualdisplay import Display

display = Display(visible=0, size=(800, 800))
display.start()

options = Options()
options.headless = True
driver = webdriver.Firefox(options=options)
driver.get("http://google.com/")
driver.quit()

And I get the following error message: 我收到以下错误消息:

Traceback (most recent call last):
  File "debug3.py", line 10, in <module>
    driver = webdriver.Firefox(options=options)
  File "/usr/local/opt/python37/lib/python3.7/site-packages/selenium/webdriver/firefox/webdriver.py", line 174, in __init__
    keep_alive=True)
  File "/usr/local/opt/python37/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__
    self.start_session(capabilities, browser_profile)
  File "/usr/local/opt/python37/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "/usr/local/opt/python37/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "/usr/local/opt/python37/lib/python3.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: connection refused

According to this thread, I included pyvirtualdisplay . 根据线程,我包括pyvirtualdisplay But there is not much difference in the outcome. 但是结果并没有太大的区别。 Also the code in this thread does not work. 同样, 线程中的代码不起作用。

I identified the problem, which was a combination of three mistakes: 我确定了问题,这是三个错误的组合:

  1. There is no need to run selenium-server-standalone 无需运行selenium-server-standalone
  2. I wasn't using the right version of geckodriver, raspbian does not have to most recent build of Firefox/Iceweasel. 我没有使用正确版本的geckodriver,因此raspbian不必安装最新版本的Firefox / Iceweasel。 The correct version for Mozilla 52 is geckodriver 0.17 The list of compatible versions is here and the releases of geckodriver are here . Mozilla 52的正确版本是geckodriver 0.17。兼容版本的列表在这里 ,geckodriver的发行版本在这里
  3. xvfb / pyvirtualdisplay is not necessary 不需要xvfb / pyvirtualdisplay

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 权限被拒绝:在 python 中运行 selenium webdriver 时出现“geckodriver.log” - Permission denied: 'geckodriver.log' while running selenium webdriver in python 如何在python中使用selenium-webdriver定位文本框 - How to locate the textbox using selenium-webdriver in python 使用 Selenium-webdriver 为 python 自动阻止 Chrome 请求? - Automate Chrome request blocking using Selenium-webdriver for python? 使用GeckoDriver和Python的Selenium firefox webdriver未知错误 - Selenium firefox webdriver unknown error using GeckoDriver and Python 如何在 python selenium-webdriver 中抓取标题 - How to grab headers in python selenium-webdriver Selenium和Geckodriver在Python中创建webdriver的问题 - Selenium and Geckodriver issue with creating a webdriver in Python Selenium-webdriver 错误 - Selenium-webdriver errors 当没有输入类型但它有 HTML 中的按钮类型时,如何使用 python selenium-webdriver 上传文件? - How to upload file using python selenium-webdriver when there is no input type but instead it has a button type in HTML? 如何从 python selenium firefox webdriver 获取 geckodriver 版本? - How do you get the geckodriver version from python selenium firefox webdriver? 在Firefox GeckoDriver中使用Python Selenium WebDriver时出现无效的安全证书错误 - Invalid Security Cert error when using Python Selenium WebDriver with Firefox GeckoDriver
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM