Install & Setup Selenium Python For Edge Browser (For Beginners)

3 min read 6 months ago
Published on Aug 17, 2024 This response is partially generated with the help of AI. It may contain inaccuracies.

Table of Contents

Introduction

This tutorial will guide you through the process of installing and setting up Selenium for Python development using the Edge browser. Selenium is a powerful tool for web automation, and this guide is designed for beginners who want to get started with Selenium 4.0+ and the Edge browser.

Step 1: Download Edge WebDriver

To use Selenium with the Edge browser, you first need to download the Edge WebDriver.

  1. Visit the Microsoft Edge WebDriver download page: Edge WebDriver
  2. Choose the version that matches your installed version of Microsoft Edge. You can check your Edge version by going to the browser, clicking on the three dots in the upper right corner, selecting 'Help and feedback', and then 'About Microsoft Edge'.
  3. Download the appropriate WebDriver for your operating system (Windows, Mac, etc.).
  4. Extract the downloaded file to a known location on your computer (e.g., C:\webdrivers).

Step 2: Install Selenium for Python

Next, you need to install the Selenium package in your Python environment.

  1. Open your command prompt (Windows) or terminal (Mac/Linux).
  2. Ensure you have Python and pip (Python package installer) installed. You can verify by running:
    python --version
    pip --version
    
  3. Install Selenium using pip by entering the following command:
    pip install selenium
    
  4. Wait for the installation to complete. You can verify the installation by running:
    pip show selenium
    

Step 3: Set Up a Sample Python Script

Create a simple Python script to test if everything is working correctly.

  1. Open your favorite code editor (e.g., VSCode, PyCharm, or even Notepad).

  2. Create a new Python file (e.g., test_edge.py).

  3. Add the following code to your script:

    from selenium import webdriver
    
    # Set the path to the Edge WebDriver
    driver_path = 'C:\\webdrivers\\msedgedriver.exe'  # adjust the path as needed
    
    # Initialize the Edge driver
    driver = webdriver.Edge(executable_path=driver_path)
    
    # Open a website
    driver.get('https://www.example.com')
    
    # Close the browser
    driver.quit()
    
  4. Save the file.

Step 4: Run the Script

Now it's time to run your script and see if it works.

  1. In your command prompt or terminal, navigate to the directory where your test_edge.py file is located.
  2. Run the script using the command:
    python test_edge.py
    
  3. If everything is set up correctly, Microsoft Edge should open and navigate to 'https://www.example.com', then close automatically.

Conclusion

You have successfully installed and set up Selenium for Python development with the Edge browser. You can now start automating your web tasks using Selenium. For further learning, consider exploring more advanced Selenium features or trying out Selenium with other browsers like Chrome or Firefox. Happy coding!