无法使用 Python 和 geckodriver 在 Raspbian 下获取 selenium-webdriver 运行
Cannot get selenium-webdriver running under Raspbian using Python and geckodriver
我正在尝试在 raspberry pi 上以无头模式获取 selenium 运行ning。我的脚本在我的 Windows 机器上工作得很好,但我就是无法让这个特定的组合工作:
- Raspbian GNU/Linux 9(拉伸)
- Python 3.7.3
- 壁虎驱动程序 0.23.0 ( 2018-10-04)
- selenium-server-standalone-3.141.59
- 火狐浏览器 52.9.0
首先,我按照 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] - 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
然后我 运行 遵循 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()
我收到以下错误消息:
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
根据 this thread, I included pyvirtualdisplay
. But there is not much difference in the outcome. Also the code in 线程不工作。
我正在尝试在 raspberry pi 上以无头模式获取 selenium 运行ning。我的脚本在我的 Windows 机器上工作得很好,但我就是无法让这个特定的组合工作:
- Raspbian GNU/Linux 9(拉伸)
- Python 3.7.3
- 壁虎驱动程序 0.23.0 ( 2018-10-04)
- selenium-server-standalone-3.141.59
- 火狐浏览器 52.9.0
首先,我按照 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] - 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
然后我 运行 遵循 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()
我收到以下错误消息:
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
根据 this thread, I included pyvirtualdisplay
. But there is not much difference in the outcome. Also the code in