How to Install selenium on windows Python

In this post, we are going to learn How to Install selenium on Windows Python. The prerequisite to install the selenium on the window is python, So we will install python step by step, later install selenium and work with how to automate web browsers on Windows with python.

The prerequisite is to install Python on Windows First


The prerequisite to installing a selenium web driver is Python. To download and install python will follow the below steps.

  • Download the latest version of Python from the official page python. The python executable file will download on our operating system. click on executable and the python installation landing page will open then click install.
  • Check “Add Python 3.10 to PATH” and click install.
  • Once the installation is complete, this window will pop-up to show the installation is successful.
  • Now, We can verify python is installed using the below command. To open a command prompt go to the window search bar and type ‘Run’.In the run bar type ‘cmd’
 python --version

2. Install selenium on window with Python


To install selenium on the window with python, We have to make sure python is already installed, else follow the above mention step to install Python., then open the command prompt and run the below command to install selenium.

pip install selenium

Sometimes the above command throw error in this case we can use pip with the -m flag. The -m flag stands for the module that is used to specify the module.

python -m pip install selenium

To update the existing version of selenium, we can use the below command

pip install –U selenium 

Once the installation of the selenium library is complete. We can verify the selenium version by using the below command.

pip show selenium

Output

Name: selenium
Version: 4.1.0
Summary:
Home-page: https://www.selenium.dev
Author:
Author-email:
License: Apache 2.0
Location: c:\users\Admin\appdata\local\programs\python\python310\lib\site-packages
Requires: urllib3, trio-websocket, trio
Required-by:

3. How to automate web browser on windows using Selenium


To make work selenium driver with web automation, we have to download a browser driver that can work with the browser of our choice.

Browers DriversLink to download
ChromeDriver https://chromedriver.chromium.org/downloads
Internet Explorerhttps://www.selenium.dev/documentation/ie_driver_server/
Microsoft Edgehttps://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/
Firefoxhttps://github.com/mozilla/geckodriver/releases
Operahttps://github.com/operasoftware/operachromiumdriver/releases

3.1 How to open Chrome Browser in Selenium Python


  • Download chromedriver from the link in the table.
  • unzip and copy chromedriver.exe to the python script directory location.
  • The path of the python script directory for us is” C:\Users\Admin\AppData\Local \Programs \Python \Python310\Scripts”. It can be different depending on what location we have chosen while installing python.
  • Run the below code to automatically open the chrome web browers.
from selenium import webdriver

driver = webdriver.Chrome()
driver.get("http://www.google.com")
print(driver.title)
driver.quit()

3.2 How to open Microsft Edge browser in selenium Python


  • Download the Microsfoftedge driver from the link in the table.
  • unzip and copy msedgedriver.exe to the python script directory location.
  • The path of the python script directory for Us is” C:\Users\Admin\AppData\Local \Programs \Python \Python310\Scripts”. It can be different depending on what location we have chosen while installing python.
  • Run the below code to automatically open the Microsft Edgebrowser.
from selenium import webdriver

driverEdge = webdriver.Edge()

driverEdge.get('https://bing.com')


driverEdge.quit()

3.3 How to open Firefox browser in selenium Python


  • Download Firefoxdriver from the link in the table. .
  • unzip and copy geckodriver.exe to the python script directory location.
  • The path of the python script directory for Us is” C:\Users\Admin\AppData\Local \Programs \Python \Python310\Scripts”. It can be different depending on what location we have chosen while installing python.
  • Run the below code to automatically open the Firefox web browser.
from selenium import webdriver
 
 
driver = webdriver.Firefox()
driver.get('https://bing.com')


driverEdge.quit()

Summary

in this post, we have learned how to Install selenium on Windows Python and web drivers setup step by step with examples.