将chromedriver与selenium/python/ubuntu一起使用 [英] Using chromedriver with selenium/python/ubuntu
问题描述
我正在尝试使用chromedriver执行一些测试,并尝试使用以下方法启动chromedriver.
I am trying to execute some tests using chromedriver and have tried using the following methods to start 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.
But none of these seems to help and the error is : selenium.common.exceptions.WebDriverException: Message: 'ChromeDriver executable needs to be available in the path.
我已经检查了多次,并且chromedriver
存在于位置/usr/local/bin
.
I have checked multiple times and chromedriver
is present in location /usr/local/bin
.
仍然我的脚本不起作用.任何机构都可以帮忙.
Still my scripts are not working. Could any body pls help.
我的google-chrome位置为:/usr/bin/google-chrome
My google-chrome location is : /usr/bin/google-chrome
推荐答案
遵循 https中的建议://askubuntu.com/questions/539498/where-does-chromedriver-install-to 我能够使它像这样工作:
Following the suggestion from https://askubuntu.com/questions/539498/where-does-chromedriver-install-to I was able to make it work like this:
-
安装了铬铬驱动器:
Installed the chromium-chromedriver:
sudo apt-get install chromium-chromedriver
将路径添加到硒线:
Adding the path to the selenium line:
driver = webdriver.Chrome("/usr/lib/chromium-browser/chromedriver")
请注意,这将打开Chromium而不是Chrome.希望对您有所帮助.
Note that this opens Chromium and not Chrome. Hope it was helpful.
这篇关于将chromedriver与selenium/python/ubuntu一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!