我在Windows 10中使用bash shell,这使得所有内容都像unix系统,我试图运行以下python2.7代码:
from selenium import webdriver
driver = webdriver.Chrome()
但是,我收到以下错误代码:
Traceback (most recent call last):
File "seleniumtest.py", line 3, in <module>
driver = webdriver.Chrome()
File "/home/eirik/.local/lib/python2.7/sitepackages/selenium/webdriver/chrome/webdriver.py", line 68, in __init__
self.service.start()
File "/home/eirik/.local/lib/python2.7/site-packages/selenium/webdriver/common/service.py", line 83, in start
os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see
https://sites.google.com/a/chromium.org/chromedriver/home
通过googeling我发现这是一个非常普遍的问题,我必须下载chromedriver并指定它的位置。所以我把上面改为:
driver = webdriver.Chrome(executable_path = r'/path/to/chromedriver.exe')
但我得到了同样的结果。之后我进入了Windows Enviroment Variable并确保将放置chromedriver的文件夹读作PATH。它是。
为了检查这个PATH是否也被bash shell读取,我写了以下内容:
echo $PATH | tr ":" "\n" | nl
在我的bash shell中。这给出了输出:
1 /home/eirik/bin
2 /home/eirik/.local/bin
3 /usr/local/sbin
4 /usr/local/bin
5 /usr/sbin
6 /usr/bin
7 /sbin
8 /bin
9 /usr/games
10 /usr/local/games
11 /mnt/c/webdriver
12 /mnt/c/Program Files (x86)/NVIDIA Corporation/PhysX/Common
13 /mnt/c/ProgramData/Oracle/Java/javapath
14 /mnt/c/Program Files (x86)/Intel/iCLS Client
15 /mnt/c/Program Files/Intel/iCLS Client
16 /mnt/c/Windows/System32
17 /mnt/c/Windows
18 /mnt/c/Windows/System32/wbem
19 /mnt/c/Windows/System32/WindowsPowerShell/v1.0
20 /mnt/c/Program Files (x86)/GtkSharp/2.12/bin
21 /mnt/c/Program Files (x86)/Skype/Phone
22 /mnt/c/Program Files (x86)/Intel/Intel(R) Management Engine Components/DAL
23 /mnt/c/Program Files/Intel/Intel(R) Management Engine Components/DAL
24 /mnt/c/Program Files (x86)/Intel/Intel(R) Management Engine Components/IPT
25 /mnt/c/Program Files/Intel/Intel(R) Management Engine Components/IPT
26 /mnt/c/Windows/System32
27 /mnt/c/Windows
28 /mnt/c/Windows/System32/wbem
29 /mnt/c/Windows/System32/WindowsPowerShell/v1.0
30 /mnt/c/Program Files (x86)/Windows Live/Shared
31 /mnt/c/Program Files/MiKTeX 2.9/miktex/bin/x64
32 /mnt/c/Users/Hauge/AppData/Local/Microsoft/WindowsApps
33 /snap/bin
34 /mnt/c/webdriver/
其中/ mnt / c / webdriver /是chromedriver.exe文件所在的位置。我不知道下一步该做什么。我已经尝试了所有我能找到的东西,但我似乎无法接受硒来接受我的chromedriver。有没有人知道该怎么做?
答案 0 :(得分:1)
我找到了解决方案! 通过将chromedriver.exe文件放在与脚本相同的文件夹中并使用./chromedriver.exe运行它,脚本可以从该文件夹访问它。
答案 1 :(得分:0)
我相信您的问题是,您正在尝试让Ubuntu子系统在需要Linux驱动程序时访问Windows驱动程序。下载linux64的chromedriver并确保它在你的路径中。