Selenium ChromeDriver On Dockers(Linux)无法关闭
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Selenium ChromeDriver On Dockers(Linux)无法关闭相关的知识,希望对你有一定的参考价值。
当我做
driver = webdriver.Chrome(binary_location,chrome_options=options)
driver.get(URL)
...
driver.close()
它引发以下错误:
'chromedriver' executable may have wrong permissions. Please see https://sites.google.com/a/chromium.org/chromedriver/home
我在码头工人上使用python 2.7图像
更改二进制文件后可执行
chmod a+x PATH_TO_DIR/chromedriver
它引发了以下错误
ERROR: Message: unknown error: failed to close window in 20 seconds
(Session info: content shell=)
(Driver info: chromedriver=2.35.528139
(47ead77cb35ad2a9a83248b292151462a66cd881),platform=Linux 4.11.0-1013-azure x86_64)
答案
错误说明了一切:
'chromedriver' executable may have wrong permissions. Please see https://sites.google.com/a/chromium.org/chromedriver/home
该错误意味着在以下代码行中:
driver = webdriver.Chrome(binary_location,chrome_options=options)
该程序期望在您传递的参数中使用chromedriver可执行文件。但无法找到chromedriver可执行文件。
所以解决方案不是将binary_location
作为参数传递,而是需要传递chromedriver二进制文件的绝对位置,如下所示:
driver = webdriver.Chrome(executable_path='/path/to/chromedriver', chrome_options=options)
driver.get(URL)
ChromeDriver会从您的系统类路径中找出默认的binary_location
并初始化Chrome浏览器
更新
如果你仍然希望明确地传递binary_location
,你可以通过Options
类传递chrome二进制文件的绝对位置,如下所示:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
options = Options()
options.add_argument("start-maximized")
options.binary_location('/path/to/chrome')
driver = webdriver.Chrome(executable_path='/path/to/chromedriver', chrome_options=options)
driver.get('http://google.com/')
以上是关于Selenium ChromeDriver On Dockers(Linux)无法关闭的主要内容,如果未能解决你的问题,请参考以下文章
Installing Selenium and ChromeDriver on Ubuntu
关于python-selenium-chromedriver提示