python - 将 chromedriver 与 selenium/python/ubuntu 一起使用

标签 python selenium selenium-webdriver selenium-chromedriver

我正在尝试使用 chromedriver 执行一些测试,并尝试使用以下方法启动 chromedriver。

driver = webdriver.Chrome('/usr/local/bin/chromedriver')

driver = webdriver.Chrome(executable_path='/usr/local/bin/chromedriver')

import os
from selenium import webdriver

chromedriver = "/usr/local/bin/chromedriver"
os.environ["webdriver.chrome.driver"] = chromedriver
driver = webdriver.Chrome(chromedriver)
driver.get("http://stackoverflow.com")

但这些似乎都没有帮助,错误是:selenium.common.exceptions.WebDriverException: Message: 'ChromeDriver executable needs to be available in the path.

我已检查多次,chromedriver 位于 /usr/local/bin 位置。

我的脚本仍然无法正常工作。任何人都可以帮忙。

我的 google-chrome 位置是:/usr/bin/google-chrome

最佳答案

遵循https://askubuntu.com/questions/539498/where-does-chromedriver-install-to 的建议我能够让它像这样工作:

  1. 安装了 chromium-chromedriver:

    sudo apt-get install chromium-chromedriver
    
  2. 添加 selenium 行的路径:

    driver = webdriver.Chrome("/usr/lib/chromium-browser/chromedriver")
    

请注意,这会打开 Chromium 而不是 Chrome。希望对您有所帮助。

关于python - 将 chromedriver 与 selenium/python/ubuntu 一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22476112/

相关文章:

javascript - 无法测试是否在 Protractor 中选中了复选框

python - 从Python中的字典值访问字符串

python - 什么时候反射(reflection)不再值得?

python-3.x - SessionNotCreatedException : Message: session not created from disconnected: unable to connect to renderer with ChromeDriver 2. 45 Chrome v71

css - 歧义匹配,找到 2 个匹配 css 的元素,如何获取第二个?

python - selenium 中的窗口处理(python)

python - Pyglet 着色器不工作,不断出错

Python——无法正确解码日本网站的标题标签

java - 这个 Sikuli 命令的 java 等价物是什么?

python - 我尝试在 Kickstarter 上获取不同项目的支持者和所在城市