【问题标题】:Selenium ChromeDriver On Dockers (Linux) failed to closeDockers (Linux) 上的 Selenium ChromeDriver 无法关闭
【发布时间】:2018-08-08 08:38:40
【问题描述】:

当我这样做时

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

我在 docker 上使用 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)

【问题讨论】:

  • 你检查this ticket了吗?
  • @Andersson 是的,将二进制文件更改为可执行并修复它

标签: python-2.7 selenium docker debian selenium-chromedriver


【解决方案1】:

错误说明了一切:

'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 会从您的System Classpath 中找出默认的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/')

【讨论】:

  • 它作为参数传递的二进制文件,也在我检查它是否找到之前,问题不存在:/
  • 是的,我通过了绝对路径,问题是我没有将二进制文件更改为可执行(更新问题)
猜你喜欢
  • 1970-01-01
  • 2020-06-27
  • 1970-01-01
  • 1970-01-01
  • 2023-02-07
  • 2014-10-07
  • 1970-01-01
  • 2020-05-09
  • 1970-01-01
相关资源
最近更新 更多