Remember to maintain security and privacy. Do not share sensitive information. Procedimento.com.br may make mistakes. Verify important information. Termo de Responsabilidade

How to Run ChromeDriver via CMD on Windows

ChromeDriver is an essential tool for automating web applications for testing purposes. It is a standalone server that implements the WebDriver protocol for Chrome. This article will guide you through the process of setting up and running ChromeDriver via the Command Prompt (CMD) on a Windows environment. ChromeDriver is crucial for developers and testers who need to automate browser interactions in their testing workflows.


Examples:


1. Download ChromeDriver:



2. Set Up Environment Variables:



  • Open the Start Menu, search for "Environment Variables", and select "Edit the system environment variables".

  • In the System Properties window, click the "Environment Variables" button.

  • In the Environment Variables window, find the "Path" variable in the "System variables" section and click "Edit".

  • Click "New" and add the path to the directory where you extracted ChromeDriver (e.g., C:\ChromeDriver).

  • Click "OK" to close all dialog boxes.


3. Verify Installation:



  • Open Command Prompt by pressing Win + R, typing cmd, and pressing Enter.

  • Type chromedriver and press Enter. You should see output indicating that ChromeDriver is running and listening on a port.


4. Running ChromeDriver with a Script:



  • Create a simple Python script to use ChromeDriver. Ensure you have Python and the Selenium package installed (pip install selenium).


  • Save the following script as test_chromedriver.py:


     from selenium import webdriver

    # Set the path to the ChromeDriver executable
    driver = webdriver.Chrome(executable_path='C:\\ChromeDriver\\chromedriver.exe')

    # Open a webpage
    driver.get('https://www.google.com')

    # Print the title of the webpage
    print(driver.title)

    # Close the browser
    driver.quit()


  • Open Command Prompt and navigate to the directory where your script is saved.

  • Run the script by typing python test_chromedriver.py and pressing Enter. This will launch Chrome, open Google's homepage, print the title, and then close the browser.


To share Download PDF

Gostou do artigo? Deixe sua avaliação!
Sua opinião é muito importante para nós. Clique em um dos botões abaixo para nos dizer o que achou deste conteúdo.