The Wayback Machine - https://web.archive.org/web/20240203023503/https://www.geeksforgeeks.org/how-to-install-selenium-in-python/
Open In App
Related Articles

How to Install Selenium in Python?

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report

Selenium Scripts are built to do some tedious tasks which can be automated using headless web browsers.
For example, Searching for some Questions on Different Search engines and storing results in a file by visiting each link. This task can take a long for a normal human being but with the help of selenium scripts one can easily do it
Now, Some of You may be wondering what is headless web browsers. It’s nothing but a browser that can be controlled using these selenium scripts for automation(web tasks). Selenium Scripts can be programmed using various languages such as JavaScript, Java, Python, etc.
How to Use selenium with Python and Linux Environment.
Python should already be installed. It can be 2.* or 3.* version. 
Steps: 
 

  1. Installing Selenium 
     
  2. Installing Webdrivers (headless) 
     
  3. Creating Simple Code 
     

 

Installing Selenium

Whatever Operating System You are Using Python command is Same for Installing Selenium Library.
First Method
Open Terminal/Cmd and Write Command as written Below
 

python -m pip install selenium

Second Method
Alternatively, you can download the source distribution here, unarchive it, and run the command below: 
 

python setup.py install

 

Installing Webdrivers

One Can Install Firefox, Chromium, PhantomJs(Deprecated Now), etc. 
 

  • for using Firefox you may need to install GeckoDriver 
     
  • for using Chrome you may need to install Chromium 
     

In this article, Firefox is used so One can Follow the Below Steps to Install:-
Steps for Linux:-
1. Go to the geckodriver releases page. Find the latest version of the driver for your platform and download it. 
For example: 
 

wget https://github.com/mozilla/geckodriver/releases/download/v0.24.0/geckodriver-v0.24.0-linux64.tar.gz

2. Extract the file with: 
 

tar -xvzf geckodriver*

3. Make it executable: 
 

chmod +x geckodriver

4. Move Files to usr/local/bin 
 

sudo mv geckodriver /usr/local/bin/

Steps for Windows:-
1. Same as Step 1 in Linux Download the GeckoDriver
2. Extract it using WinRar or any application you may have.
3. Add it to Path using Command Prompt
 

setx path "%path%;GeckoDriver Path"

For Example:- 
 

setx path "%path%;c:/user/eliote/Desktop/geckodriver-v0.26.0-win64/geckodriver.exe"

 

Creating Simple Code

 

Python3




# Python program to demonstrate
# selenium
 
 
from selenium import webdriver
 
 
driver = webdriver.Firefox()
driver.get("https://google.co.in")


Output:
 

python-selenium

 

Don't miss your chance to ride the wave of the data revolution! Every industry is scaling new heights by tapping into the power of data. Sharpen your skills and become a part of the hottest trend in the 21st century.

Dive into the future of technology - explore the Complete Machine Learning and Data Science Program by GeeksforGeeks and stay ahead of the curve.


Last Updated : 28 Jan, 2022
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads
Complete Tutorials