下载zip文件后,我将zip文件解压缩到我的下载文件夹中。然后,我将可执行二进制文件(C:\ Users \ michael \ Downloads \ chromedriver_win32)的路径放入环境变量“路径”中。
但是,当我运行以下代码时:
from selenium import webdriver
driver = webdriver.Chrome()
…我不断收到以下错误消息:
WebDriverException:Message:'chromedriver' executable needs to be available in the path.Please look at http://docs.seleniumhq.org/download/#thirdPartyDrivers and read up at http://code.google.com/p/selenium/wiki/ChromeDriver
After downloading the zip file, I unpacked the zip file to my downloads folder. Then I put the path to the executable binary (C:\Users\michael\Downloads\chromedriver_win32) into the Environment Variable “Path”.
However, when I run the following code:
from selenium import webdriver
driver = webdriver.Chrome()
… I keep getting the following error message:
WebDriverException: Message: 'chromedriver' executable needs to be available in the path. Please look at http://docs.seleniumhq.org/download/#thirdPartyDrivers and read up at http://code.google.com/p/selenium/wiki/ChromeDriver
But – as explained above – the executable is(!) in the path … what is going on here?
You can test if it actually is in the PATH, if you open a cmd and type in chromedriver (assuming your chromedriver executable is still named like this) and hit Enter. If Starting ChromeDriver 2.15.322448 is appearing, the PATH is set appropriately and there is something else going wrong.
Alternatively you can use a direct path to the chromedriver like this:
Same situation with pycharm community edition, so, as for cmd, you must restart your ide in order to reload path variables. Restart your ide and it should be fine.
Some additional input/clarification for future readers of this thread,
to avoid tinkering with the PATH env. variable at the Windows level and restart of the Windows system:
(copy of my answer from https://stackoverflow.com/a/49851498/9083077 as applicable to Chrome):
(1) Download chromedriver (as described in this thread earlier) and place the (unzipped) chromedriver.exe at X:\Folder\of\your\choice
(2) Python code sample:
import os;
os.environ["PATH"] += os.pathsep + r'X:\Folder\of\your\choice';
from selenium import webdriver;
browser = webdriver.Chrome();
browser.get('http://localhost:8000')
assert 'Django' in browser.title
Notes:
(1) It may take about 5 seconds for the sample code (in the referenced answer) to open up the Firefox browser for the specified url.
(2) The python console would show the following error if there’s no server already running at the specified url or serving a page with the title containing the string ‘Django’:
assert ‘Django’ in browser.title
AssertionError
回答 6
对于Linux和OSX
步骤1:下载chromedriver
# You can find more recent/older versions at http://chromedriver.storage.googleapis.com/# Also make sure to pick the right driver, based on your Operating System
wget http://chromedriver.storage.googleapis.com/81.0.4044.69/chromedriver_mac64.zip
# You can find more recent/older versions at http://chromedriver.storage.googleapis.com/
# Also make sure to pick the right driver, based on your Operating System
wget http://chromedriver.storage.googleapis.com/81.0.4044.69/chromedriver_mac64.zip
For debian: wget https://chromedriver.storage.googleapis.com/2.41/chromedriver_linux64.zip
When you unzip chromedriver, please do specify an exact location so that you can trace it later. Below, you are getting the right chromedriver for your OS, and then unzipping it to an exact location, which could be provided as argument later on in your code.
If you are working with robot framework RIDE. Then you can download Chromedriver.exe from its official website and keep this .exe file in C:\Python27\Scripts directory. Now mention this path as your environment variable eg. C:\Python27\Scripts\chromedriver.exe.
Restart your computer and run same test case again. You will not get this problem again.
Could try to restart computer if it doesn’t work after you are quite sure that PATH is set correctly.
In my case on windows 7, I always got the error on WebDriverException: Message: for chromedriver, gecodriver, IEDriverServer. I am pretty sure that i have correct path. Restart computer, all work
In my case, this error disappears when I have copied chromedriver file to c:\Windows folder. Its because windows directory is in the path which python script check for chromedriver availability.
If you are using remote interpreter you have to also check if its executable PATH is defined. In my case switching from remote Docker interpreter to local interpreter solved the problem.
I encountered the same problem as yours.
I’m using PyCharm to write programs, and I think the problem lies in environment setup in PyCharm rather than the OS.
I solved the problem by going to script configuration and then editing the PATH in environment variables manually.
Hope you find this helpful!
The best way is maybe to get the current directory and append the remaining address to it.
Like this code(Word on windows. On linux you can use something line pwd):
webdriveraddress = str(os.popen("cd").read().replace("\n", ''))+'\path\to\webdriver'
回答 17
当我下载chromedriver.exe时,我只是将其移动到PATH文件夹C:\ Windows \ System32 \ chromedriver.exe中,却遇到了完全相同的问题。
对我来说,解决方案是只更改PATH中的文件夹,因此我将其移到了PATH中也位于Pycharm Community bin文件夹中。例如:
C:\ Windows \ System32 \ chromedriver.exe->给我exceptions
C:\ Program Files \ JetBrains \ PyCharm Community Edition 2019.1.3 \ bin \ chromedriver.exe->运行正常
When I downloaded chromedriver.exe I just move it in PATH folder C:\Windows\System32\chromedriver.exe and had exact same problem.
For me solution was to just change folder in PATH, so I just moved it at Pycharm Community bin folder that was also in PATH.
ex:
C:\Windows\System32\chromedriver.exe –> Gave me exception
C:\Program Files\JetBrains\PyCharm Community Edition
2019.1.3\bin\chromedriver.exe –> worked fine
回答 18
Mac Mojave运行机器人测试框架和Chrome 77时出现了此问题。这解决了问题。感谢@Navarasu将我指向正确的轨道。
$ pip install webdriver-manager --user # install webdriver-manager lib for python
$ python # open python prompt
接下来,在python提示符下:
from selenium import webdriver
from webdriver_manager.chrome importChromeDriverManager
driver = webdriver.Chrome(ChromeDriverManager().install())# ctrl+d to exit
这导致以下错误:
Checkingfor mac64 chromedriver:xx.x.xxxx.xx in cache
Thereis no cached driver.Downloading new one...Trying to download new driver from http://chromedriver.storage.googleapis.com/xx.x.xxxx.xx/chromedriver_mac64.zip
...TypeError: makedirs() got an unexpected keyword argument 'exist_ok'
Had this issue with Mac Mojave running Robot test framework and Chrome 77. This solved the problem. Kudos @Navarasu for pointing me to the right track.
$ pip install webdriver-manager --user # install webdriver-manager lib for python
$ python # open python prompt
Next, in python prompt:
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
driver = webdriver.Chrome(ChromeDriverManager().install())
# ctrl+d to exit
This leads to the following error:
Checking for mac64 chromedriver:xx.x.xxxx.xx in cache
There is no cached driver. Downloading new one...
Trying to download new driver from http://chromedriver.storage.googleapis.com/xx.x.xxxx.xx/chromedriver_mac64.zip
...
TypeError: makedirs() got an unexpected keyword argument 'exist_ok'
(for Mac users)
I have the same problem but i solved by this simple way:
You have to put your chromedriver.exe in the same folder to your executed script and than in pyhton write this instruction :