WebDriverException: Service U:/Scraping/chromedriver.exe unexpectedly exited. Status code was: 1 while working with Chrome and Python
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 webdriverdriver = webdriver.Chrome(executable_path=r'U:\Scraping\chromedriver.exe')driver.get(url)
Additional Consideration
Ensure that you have downloaded the exact format of the ChromeDriver binary from the download location pertaining to your underlying OS among:
- chromedriver_win32.zip: For Windows OS
Ensure that ChromeDriver binary have executable permission for the non-administrator user.
- Execute your Test as a non-administrator user.
- Another potential reason for the error can be due to missing the entry
127.0.0.1 localhost
in/etc/hosts
Solution
Windows OS - Add
127.0.0.1 localhost
to/etc/hosts
Mac OSX - Ensure the following entries:
127.0.0.1 localhost255.255.255.255 broadcasthost::1 localhostfe80::1%lo0 localhost
References
As per the discussion in selenium.common.exceptions.WebDriverException: Message: Can not connect to the Service geckodriver:
- Selenium does not require
127.0.0.1 localhost
to be explicitly set in the host file. - However it is mandatory requirement to map localhost to the IPv4 local loopback (127.0.0.1)
- The mechanism of this mapping does not have to be through the hosts file always.
- On Windows OS systems it is not mapped in the hosts file at all (resolving localhost is done by the DNS resolver).
TL;DR
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.
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))