What is Selenium and how to use Selenium Testing in Python language

Posted By :Preeti Choudhary |30th July 2022

Selenium WebDriver is a framework for browser automation that receives instructions and sends them to a browser. A popular web-based automation testing tool Selenium WebDriver mostly used for automating Web UI testing activities. It supports Browser Mozilla Firefox, Internet Explorer, Google Chrome, Safari, Opera Etc.


 

How to Install Selenium on Chrome Browser -

 

  1. sudo apt-get install python3.8 -y

 

  1. sudo apt-get install python3-pip -y

 

  1. pip3 install selenium

 

  1. sudo dpkg -I google-chrome-stable_current_amd64.deb

 

  1. Install Chromedriver Extension:

 

  wget https://chromedriver.storage.googleapis.com/92.0.4515.107/chromedriver_linux64.zip

 

  1. You will receive a zip file; you must unzip it:

 

 unzip chromedriver_linux64.zip

 

  1. You then need to move the file to the correct location, so you can find it when you need it

 

  sudo mv chromedriver /usr/bin/chromedriver

 

  sudo chown root: root /usr/bin/chromedriver 

 

  sudo chmod +x /usr/bin/chromedriver

 

8.  Pycharm- Go to Settings and install Selenium inside the Python interpreter.



 

 How to Perform Testing in selenium-

 

  1. First import web driver in selenium.

 

  1. We have multiple browsers so we can download its extension and use it.

 

  1. driver. get method will navigate to a page, For whatever application you want to test, enter the URL of that application.

 

  1. To access the HTML code, utilise the.page_source attribute.

 

  1. Selenium Python follows different locating strategies for elements (ID, NAME, CLASS)





 

Command line - 

 

We are using this command line to perform selenium testing

 

  • from selenium import webdriver
  • from selenium.webdriver.common.by import By
  • from selenium.webdriver.common.keys import Keys
  • from selenium.webdriver.support.ui import WebDriverWait
  • from selenium.webdriver.support.expected_conditions import presence_of_element_located


 

send_keys()-Inserts data into the input field through send_keys.

 

Click()-click is used to click any button


 

Locating Strategies - Locators Strategies are methods used to locate elements from the page and perform an operation on the same and attribute value matching the location will be returned. Selenium Python uses a variety of element finding techniques.


 

  1. find_element_by_id

 

  1. find_element_by_name

 

  1. find_element_by_class

 

  1. find_element_by_link_text

 

  1. find_element_by_partial_link_text


 

Create a project and go to the python file and add the following code:


 

Example of Selenium Testing-

 


 

Run Scripts-

 


 

OUTPUT -

 


 


About Author

Preeti Choudhary

Preeti is an exceptionally skilled Quality Analyst with expertise in various testing methodologies, including Manual Testing for both web and mobile applications, as well as Automation Testing specifically for web applications. She is well-versed in API Testing, Database Testing, and CBT Testing. She has extensive experience working with bug-tracking tools like JIRA and Trello, enabling her to effectively track and manage issues throughout the testing process. She has made significant contributions to the success of various internal and client projects, including Enviuver, Heartbeat, OCR, TripCongo, ESP Safety OCR, and Hydroleap Website Development. Preeti's expertise in Manual Testing has allowed her to identify defects and ensure the smooth functionality of applications across both web and mobile platforms. She is dedicated to delivering high-quality work and ensuring the success of the projects she contributes to.

Request For Proposal

[contact-form-7 404 "Not Found"]

Ready to innovate ? Let's get in touch

Chat With Us