Install & Setup Selenium Python For Edge Browser (For Beginners)
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.
- Visit the Microsoft Edge WebDriver download page: Edge WebDriver
- 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'.
- Download the appropriate WebDriver for your operating system (Windows, Mac, etc.).
- 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.
- Open your command prompt (Windows) or terminal (Mac/Linux).
- Ensure you have Python and pip (Python package installer) installed. You can verify by running:
python --version pip --version
- Install Selenium using pip by entering the following command:
pip install selenium
- 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.
-
Open your favorite code editor (e.g., VSCode, PyCharm, or even Notepad).
-
Create a new Python file (e.g.,
test_edge.py
). -
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()
-
Save the file.
Step 4: Run the Script
Now it's time to run your script and see if it works.
- In your command prompt or terminal, navigate to the directory where your
test_edge.py
file is located. - Run the script using the command:
python test_edge.py
- 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!