Reputation: 711
I just uninstalled Chrome because it was acting strange (fixed now) and after this Selenium in Python is not able to identify the Chrome driver binary, which is extremely strange because it should be completely unaffected and it is in a different location and a different version from the chrome I use on my desktop, code is as follows and has worked for years now.
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--load-extension='+exension_path)
driver = webdriver.Chrome(executable_path=chrome_driver_folder,options=chrome_options)
Anyone has any idea what on earth is going on? I get the follow error:
WebDriverException: Message: unknown error: cannot find Chrome binary
(Driver info: chromedriver=2.40.565498 (ea082db3280dd6843ebfb08a625e3eb905c4f5ab),platform=Windows NT 10.0.18362 x86_64)
Upvotes: 1
Views: 21347
Reputation: 11
Automatically get the chrome binary path depending upon your OS:
This function checks the current operating system using platform.system() and returns the expected path to the Chrome binary.
It handles default Chrome locations on:
If the OS is not one of the above, an exception is raised.
The return value can be used to set the binary_location in Selenium's ChromeOptions.
import platform
def get_chrome_binary():
# Check the operating system and set the Chrome binary path accordingly
if platform.system() == "Darwin": # macOS
binary_location = '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome'
elif platform.system() == "Linux": # Linux-based system (e.g., Ubuntu Docker container)
binary_location = '/usr/bin/google-chrome'
elif platform.system() == "Windows": # Windows
# Provide the path to the Chrome executable on Windows
binary_location = 'C:/Program Files (x86)/Google/Chrome/Application/chrome.exe' # Adjust the path as needed
else:
raise Exception("Unsupported operating system") # You can handle other OSes based on your requirements
return binary_location
Upvotes: 1
Reputation: 193058
This error message...
WebDriverException: Message: unknown error: cannot find Chrome binary (Driver info: chromedriver=2.40.565498 (ea082db3280dd6843ebfb08a625e3eb905c4f5ab),platform=Windows NT 10.0.18362 x86_64)
...implies that the ChromeDriver was unable to initiate/spawn a new Browsing Context i.e. Chrome Browser session.
Your main issue is the incompatibility between the version of the binaries you are using as follows:
Supports Chrome v66-68
Supports Chrome version 85
So there is a clear mismatch between ChromeDriver v2.40 and the Chrome Browser v85.0
Ensure that:
@Test
as non-root user.driver.quit()
within tearDown(){}
method to close & destroy the WebDriver and Web Client instances gracefully.Upvotes: 5
Reputation: 887
In order to have a clean code and to stop track the chrome path/version, I recommend to you to use webdriver_manager
Install it
pip install webdriver_manager
and use it like this
from webdriver_manager.chrome import ChromeDriverManager
options = webdriver.ChromeOptions()
chrome_options.add_argument('--load-extension='+exension_path)
driver = webdriver.Chrome(executable_path=ChromeDriverManager().install(), options=options)
but if don't want to use it here is the code for local browser
chrome_options = Options()
chrome_options.add_argument('--load-extension='+exension_path)
chrome_options.binary_location = 'YOUR_PATH'
driver = webdriver.Chrome(executable_path=os.path.abspath(“chromedriver"), chrome_options=chrome_options)
but I totally recommend using the first version.
Upvotes: 0