Reputation: 560
I've been trying to get the webdriver to work with Python in Chrome at work, but can't for the life of me figure out what's wrong, despite troubleshooting for most of the day.
I've unzipped chromedriver to the folder I'm working in. I've tried using the executable_path
argument with chromedriver. I've tried updating the options within chromedriver to direct to the Chrome.exe file.
Code is below. Pretty straightforward. 'url' has an address from earlier in the code that I'm not including here - the script doesn't even make it that far anyways.
from selenium import webdriver
driver = webdriver.Chrome(executable_path = 'U:/Scraping/chromedriver.exe')
driver.get(url)
And the error:
Traceback (most recent call last):
File "<ipython-input-67-db2ce2aa7cdf>", line 1, in <module>
runfile('U:/Scraping/Project.py', wdir='U:/Scraping')
File "C:\ProgramData\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 705, in runfile
execfile(filename, namespace)
File "C:\ProgramData\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 102, in execfile
exec(compile(f.read(), filename, 'exec'), namespace)
File "U:/Scraping/Project.py", line 14, in <module>
driver = webdriver.Chrome(executable_path = 'U:/Scraping/chromedriver.exe')
File "C:\ProgramData\Anaconda3\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 68, in __init__
self.service.start()
File "C:\ProgramData\Anaconda3\lib\site-packages\selenium\webdriver\common\service.py", line 98, in start
self.assert_process_still_running()
File "C:\ProgramData\Anaconda3\lib\site-packages\selenium\webdriver\common\service.py", line 111, in assert_process_still_running
% (self.path, return_code)
WebDriverException: Service U:/Scraping/chromedriver.exe unexpectedly exited. Status code was: 1
Upvotes: 6
Views: 14212
Reputation: 1254
I had a similar experience to @rvictordelta. For some reason I could no longer edit the location where the driver was through python, and when I changed to a shared drive for work that wouldn't work as well. Finally, used this code below. This version is good because it checks for the most up to date chrome driver. If the driver exists it simply uses it, but if not it will download and install it.
custom_path=r'C:\Users\username'
driver = webdriver.Chrome(ChromeDriverManager(path=custom_path).install(),options=chrome_options))
Upvotes: 1
Reputation: 668
Same error here. My issue was that I had chromedriver.exe
on a company sharedrive. Some firewall or security setting was presumably preventing python from accessing the executable file in that remote location.
I made chromedriver.exe
local and it worked.
Upvotes: 4
Reputation: 193058
While passing the absolute path of the ChromeDriver binary through the argument executable_path you need to mention the path within single quotes (i.e. ''
) seperated by a single forward slash (i.e. \
) along with the raw switch (i.e. r
) as follows:
from selenium import webdriver
driver = webdriver.Chrome(executable_path=r'U:\Scraping\chromedriver.exe')
driver.get(url)
Ensure that you have downloaded the exact format of the ChromeDriver binary from the download location pertaining to your underlying OS among:
Ensure that ChromeDriver binary have executable permission for the non-administrator user.
127.0.0.1 localhost
in /etc/hosts
Windows OS - Add 127.0.0.1 localhost
to /etc/hosts
Mac OSX - Ensure the following entries:
127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost
fe80::1%lo0 localhost
As per the discussion in selenium.common.exceptions.WebDriverException: Message: Can not connect to the Service geckodriver:
127.0.0.1 localhost
to be explicitly set in the host file.How to reset the Hosts file back to the default
Upvotes: 1