在 Chromebook 上 运行 Selenium 需要哪些版本的 Chromium、Selenium 和 Chromedriver?
Which versions of Chromium, Selenium and Chromedriver are required to run Selenium on a Chromebook?
我想 运行 在 Chrome 本书上使用 Chrome 驱动程序进行 Selenium 测试,但我无法让它工作。
设置
我有 crouton and chromebrew installed. chromebrew has packages for virtualenv and Python3.6, plus with pip install Selenium
I got Selenium. From the ChromeDriver ChromeOS documentation 我知道 chromedriver 在 /usr/local/chromedriver
中。调用它:
chronos@localhost /usr/local/chromedriver $ chromedriver
Starting ChromeDriver 2.24 on port 9515
Only local connections are allowed.
给我版本,我只想测试 localhost
所以我很好并且有:
Versions:
ChromiumOS 55.0.2883.100 (64-bit)
Python 3.6
Selenium bindings for Python 3.13.0
Chromedriver 2.24
我(认为我)了解 Chrome 驱动程序的行为就像端口 9515 上的服务器等待来自 test.py
的调用。我一直在摆弄,直到我不再因为缺少 chromedriver/permissions/etc.
而出错
测试文件
我的测试文件只包含:
from selenium import webdriver
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--no-sandbox')
chrome_options.binary_location = '/etc/chromium.exe'
driver = webdriver.Chrome('/usr/local/chromedriver/chromedriver', chrome_options=chrome_options)
driver.get("http://localhost:8000")
如果我调用 python3 test.py
或 get("http://localhost:8000")
没有任何反应,而在我的 python3 调用中,我最终得到:
Traceback (most recent call last):
File "test.py", line 6, in <module>
driver = webdriver.Chrome('/usr/local/chromedriver/chromedriver', chrome_options=chrome_options)
File "/usr/local/demo/venv/lib/python3.6/site-packages/selenium/webdriver/chrome/webdriver.py", line 75, in __init__
desired_capabilities=desired_capabilities)
File "/usr/local/demo/venv/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 156, in __init__
self.start_session(capabilities, browser_profile)
File "/usr/local/demo/venv/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 251, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "/usr/local/demo/venv/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 320, in execute
self.error_handler.check_response(response)
File "/usr/local/demo/venv/lib/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: chrome not reachable
(Driver info: chromedriver=2.24,platform=Linux 3.14.0 x86_64)
我还在 chromedriver documentation 上找到了这个测试脚本到 运行 chromedriver 作为服务,结果与上面相同:
import time
from selenium import webdriver
import selenium.webdriver.chrome.service as service
service = service.Service('/usr/local/chromedriver/chromedriver')
service.start()
capabilities = {'chrome.binary': '/etc/chromium.exe'}
driver = webdriver.Remote(service.service_url, capabilities)
driver.get('http://localhost:8000');
time.sleep(5) # Let the user actually see something!
driver.quit()
您会看到我在功能中将 Chrome 替换为自定义 Chromium。从 chromedriver documentation and this 这是用自定义二进制文件替换默认 Chrome 二进制文件的方法。
我从这个 github issue that the problem could be that versions of components don't play nice with each other, but the Chromedriver documentation 了解到它指向并没有真正告诉我从哪里开始寻找要尝试的版本。
我想我已经涵盖了除了不兼容版本之外的所有情况,所以问题是,谁能告诉我哪个版本可以得到这个 运行?
这个错误信息...
selenium.common.exceptions.WebDriverException: Message: chrome not reachable
...意味着 ChromeDriver 无法 initiate/spawn 一个新的 WebBrowser 即 Chrome 浏览器 会话。
除此错误之外还有多种可能性如下:
因为你在 Linux OS 而你提到 chromium[= 的绝对路径97=] 二进制文件,你需要去除扩展名,即 .exe
如下:
chrome_options.binary_location = '/etc/chromium'
当您初始化 Chrome 浏览会话时,您需要传递两个参数 chrome_options和executable_path如下:
driver = webdriver.Chrome(executable_path='/usr/local/chromedriver/chromedriver', chrome_options=chrome_options)
就像常规 Chrome 浏览器 GA 发布一样,Chrome 团队 发布ChromeDriver 二进制文件具有 added/modified 功能以及相应支持的 Chrome 浏览器 版本。您需要确保您使用的 chrome
和 chromedriver
二进制文件在 Release Notes.
之后同步
You can find a related discussion on versioning in Selenium for ChromeDriver and Chrome Browser
但是,您的主要问题是您使用的二进制文件版本之间 不兼容,如下所示:
- 您正在使用 chromedriver=2.24
- chromedriver=2.24 的发行说明清楚地提到了以下内容:
Supports Chrome v52-54
- 您正在使用 chrome=55.0
- ChromeDriver v2.27 的发行说明清楚地提到了以下内容:
Supports Chrome v54-56
所以 ChromeDriver v2.24 和 Chrome Browser v55.0[=94= 之间存在明显的不匹配]
解决方案
- 将Chrome驱动程序升级到当前ChromeDriver v2.40级别。
- 保持Chrome版本在Chromev66-68[=94=之间] 水平。 (as per ChromeDriver v2.40 release notes)
- 通过 IDE 和 [=46] 清理 您的 项目工作区 =]重建你的项目只需要依赖。
- (LinuxOS only) Free Up and Release the Unused/Cached Memory in Ubuntu/Linux Mint 测试套件[=97]执行前后=].
- 如果您的基础 Web 客户端 版本太旧,则通过 Revo Uninstaller 卸载它并安装最新的 GA 和发布版本的 Web 客户端.
- 系统重启。
- 执行你的
@Test
.
我想 运行 在 Chrome 本书上使用 Chrome 驱动程序进行 Selenium 测试,但我无法让它工作。
设置
我有 crouton and chromebrew installed. chromebrew has packages for virtualenv and Python3.6, plus with pip install Selenium
I got Selenium. From the ChromeDriver ChromeOS documentation 我知道 chromedriver 在 /usr/local/chromedriver
中。调用它:
chronos@localhost /usr/local/chromedriver $ chromedriver
Starting ChromeDriver 2.24 on port 9515
Only local connections are allowed.
给我版本,我只想测试 localhost
所以我很好并且有:
Versions:
ChromiumOS 55.0.2883.100 (64-bit)
Python 3.6
Selenium bindings for Python 3.13.0
Chromedriver 2.24
我(认为我)了解 Chrome 驱动程序的行为就像端口 9515 上的服务器等待来自 test.py
的调用。我一直在摆弄,直到我不再因为缺少 chromedriver/permissions/etc.
测试文件
我的测试文件只包含:
from selenium import webdriver
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--no-sandbox')
chrome_options.binary_location = '/etc/chromium.exe'
driver = webdriver.Chrome('/usr/local/chromedriver/chromedriver', chrome_options=chrome_options)
driver.get("http://localhost:8000")
如果我调用 python3 test.py
或 get("http://localhost:8000")
没有任何反应,而在我的 python3 调用中,我最终得到:
Traceback (most recent call last):
File "test.py", line 6, in <module>
driver = webdriver.Chrome('/usr/local/chromedriver/chromedriver', chrome_options=chrome_options)
File "/usr/local/demo/venv/lib/python3.6/site-packages/selenium/webdriver/chrome/webdriver.py", line 75, in __init__
desired_capabilities=desired_capabilities)
File "/usr/local/demo/venv/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 156, in __init__
self.start_session(capabilities, browser_profile)
File "/usr/local/demo/venv/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 251, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "/usr/local/demo/venv/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 320, in execute
self.error_handler.check_response(response)
File "/usr/local/demo/venv/lib/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: chrome not reachable
(Driver info: chromedriver=2.24,platform=Linux 3.14.0 x86_64)
我还在 chromedriver documentation 上找到了这个测试脚本到 运行 chromedriver 作为服务,结果与上面相同:
import time
from selenium import webdriver
import selenium.webdriver.chrome.service as service
service = service.Service('/usr/local/chromedriver/chromedriver')
service.start()
capabilities = {'chrome.binary': '/etc/chromium.exe'}
driver = webdriver.Remote(service.service_url, capabilities)
driver.get('http://localhost:8000');
time.sleep(5) # Let the user actually see something!
driver.quit()
您会看到我在功能中将 Chrome 替换为自定义 Chromium。从 chromedriver documentation and this
我从这个 github issue that the problem could be that versions of components don't play nice with each other, but the Chromedriver documentation 了解到它指向并没有真正告诉我从哪里开始寻找要尝试的版本。
我想我已经涵盖了除了不兼容版本之外的所有情况,所以问题是,谁能告诉我哪个版本可以得到这个 运行?
这个错误信息...
selenium.common.exceptions.WebDriverException: Message: chrome not reachable
...意味着 ChromeDriver 无法 initiate/spawn 一个新的 WebBrowser 即 Chrome 浏览器 会话。
除此错误之外还有多种可能性如下:
因为你在 Linux OS 而你提到 chromium[= 的绝对路径97=] 二进制文件,你需要去除扩展名,即
.exe
如下:chrome_options.binary_location = '/etc/chromium'
当您初始化 Chrome 浏览会话时,您需要传递两个参数 chrome_options和executable_path如下:
driver = webdriver.Chrome(executable_path='/usr/local/chromedriver/chromedriver', chrome_options=chrome_options)
就像常规 Chrome 浏览器 GA 发布一样,Chrome 团队 发布ChromeDriver 二进制文件具有 added/modified 功能以及相应支持的 Chrome 浏览器 版本。您需要确保您使用的
chrome
和chromedriver
二进制文件在 Release Notes. 之后同步
You can find a related discussion on versioning in
Selenium for ChromeDriver and Chrome Browser
但是,您的主要问题是您使用的二进制文件版本之间 不兼容,如下所示:
- 您正在使用 chromedriver=2.24
- chromedriver=2.24 的发行说明清楚地提到了以下内容:
Supports Chrome v52-54
- 您正在使用 chrome=55.0
- ChromeDriver v2.27 的发行说明清楚地提到了以下内容:
Supports Chrome v54-56
所以 ChromeDriver v2.24 和 Chrome Browser v55.0[=94= 之间存在明显的不匹配]
解决方案
- 将Chrome驱动程序升级到当前ChromeDriver v2.40级别。
- 保持Chrome版本在Chromev66-68[=94=之间] 水平。 (as per ChromeDriver v2.40 release notes)
- 通过 IDE 和 [=46] 清理 您的 项目工作区 =]重建你的项目只需要依赖。
- (LinuxOS only) Free Up and Release the Unused/Cached Memory in Ubuntu/Linux Mint 测试套件[=97]执行前后=].
- 如果您的基础 Web 客户端 版本太旧,则通过 Revo Uninstaller 卸载它并安装最新的 GA 和发布版本的 Web 客户端.
- 系统重启。
- 执行你的
@Test
.