📌  相关文章
📜  chromedriver location windows 10 (1)

📅  最后修改于: 2023-12-03 14:40:05.268000             🧑  作者: Mango

Chromedriver Location on Windows 10

Chromedriver is a standalone executable file that enables communication between Selenium WebDriver and the Chrome Browser. In order to use Selenium WebDriver for automating tests on the Chrome Browser, the path to the Chromedriver executable file must be set in the system's environment variables.

Downloading Chromedriver

Chromedriver can be downloaded from the official Selenium website - https://sites.google.com/a/chromium.org/chromedriver/downloads. The version of the Chromedriver downloaded should match the version of the installed Chrome Browser.

Once downloaded, the Chromedriver executable file should be saved in a directory on the system.

Setting Chromedriver in the System's Environment Variables

To set the path to the Chromedriver executable file in the system's environment variables, follow the below steps:

  1. Open the Start menu and search for "environment variables".
  2. Click on "Edit the system environment variables".
  3. In the System Properties window that opens, click on the "Environment Variables" button.
  4. Under "System Variables", scroll down and select "Path". Click on the "Edit" button.
  5. Click on the "New" button and add the directory path where the Chromedriver executable file is saved. Click on "Ok" and close all windows.

The path to the Chromedriver executable file is now set in the system's environment variables and can be used to drive the Chrome Browser using Selenium WebDriver.

Example Usage

Here is an example code snippet in Python showing how to use the Chromedriver in Selenium WebDriver:

from selenium import webdriver

# Set Chromedriver location as an environment variable
chromedriver_location = r"C:\path\to\chromedriver.exe"
webdriver.Chrome(chromedriver_location)

# Navigate to a website and search for a term
driver.get("https://www.google.com")
search_box = driver.find_element_by_name("q")
search_box.send_keys("Selenium WebDriver")
search_box.submit()

# Close the browser window
driver.quit()
Conclusion

In summary, setting the path to the Chromedriver executable file in the system's environment variables is a necessary step for using Selenium WebDriver to automate tests on the Chrome Browser. The downloaded Chromedriver executable file should be saved in a directory on the system and its location should be added to the Path environment variable. Once this is done, the Chromedriver can be used in automation scripts to drive the Chrome Browser.