“OpenQA.Selenium.WebDriverException: unknown error: cannot find Chrome binary”
Are you encountering the following error while running Selenium UI tests? This error typically occurs when Selenium cannot locate the Chrome driver on your system, particularly on Windows machines used for running Selenium UI tests.
OpenQA.Selenium.WebDriverException : unknown error: cannot find Chrome binary
Set the Chrome Driver Path:
- Option 1: Hardcode the Path in Your Script:
- Explicitly specify the path to your Chrome driver within your code. For example, in Python:
from selenium import webdriver driver_path = "C:\path\to\chromedriver.exe" driver = webdriver.Chrome(executable_path=driver_path)
Use code with caution.content_copy - Option 2: Install Chrome Driver Explicitly:
- If hardcoding the path isn’t ideal, download and install the compatible Chrome driver version from the official source: https://chromedriver.chromium.org/downloads.
Address Missing Path Variable (Optional):
- While less common, sometimes the error arises due to a missing path variable for
Chrome.exe
. To check and potentially add the path:- Windows:
- Right-click on “This PC” -> “Properties” -> “Advanced system settings” -> “Environment Variables.”
- Under “System variables,” find “Path” and click “Edit.”
- If the path to your Chrome installation directory (e.g.,
C:\Program Files\Google\Chrome\Application\
) is absent, add it and save the changes.
- Windows:
By following these steps, you should be able to resolve the “unknown error: cannot find Chrome binary” issue and successfully execute your Selenium UI tests!
Additional Tips:
- Download the latest compatible Chrome driver version to avoid compatibility issues.
- Double-check your code for any typos in the driver path.
- If you’re using a continuous integration (CI) environment, ensure the Chrome driver is accessible to the build agents.