View All
View All
View All
View All
View All
View All
View All
View All
View All
View All
View All
View All
View All

Selenium Tutorial: Everything you need to Learn

By Pavan Vadapalli

Updated on Nov 24, 2022 | 7 min read | 6.2k views

Share:

Software testing is a crucial part of software development. While it is possible to test software manually, it leaves room for errors. In addition, the manual method is time-consuming, demanding the tester to be constantly present. Therefore, using automation tools for software testing is better as they are effective in avoiding errors while making the software testing process easier. 

One of the most popular tools for automated software testing is Selenium. This blog discusses what Selenium is and its features.

Check out our free courses related to software development.

What is Selenium?

Selenium is an open-source automated software encompassing a collection of tools used for testing web applications on multiple browsers. It is a simple framework developed on JavaScript that allows users to test their applications on various browsers like Opera, Google Chrome, and Mozilla Firefox. 

There are four main types of Selenium tools:

  • Selenium RC- This tool allows the users to upload their web or mobile application UI scripts for testing. It is effective in testing complex scripts.
  • Selenium WebDriver- It is one of the most essential and widely used selenium tools that allow testing of scripts through programming or script-based interface.
  • Selenium Integrated Development Environment (IDE)- This tool works on Firefox, Chrome, and Opera and facilitates playback of test scripts written in Python, Java, HTML, and Ruby.
  • Selenium Grid- The Selenium grid is used to test scripts of different browsers or servers. It is mainly used for running tests in a parallel environment.

Selenium Tutorial

The following are all the things you should know if a Selenium Tutorial:

1. Setting up the environment:-

Before you start using Selenium, you need to set up or install it on your laptop or computer. Here is how you can do it:

  • Download and Install Java- The first step is to download and install the Java Development Kit on your laptop through the URL ‘http://www.oracle.com/technetwork/java/javase/downloads/index.html’
  • Download and Configure Eclipse- After downloading and installing Java, the next step is to download and configure eclipse through the URL http://www.eclipse.org/downloads/. It is downloaded in a zip format. You can unzip the file, install it, and configure eclipse.
  • Configure FireBug and FirePath– To work with Selenium RC or web driver, you will need FireBug and FirePath Plugin that you can download from https://addons.mozilla.org/en-US/firefox/addon/firebug/ and download the plugin.
  • Configure Selenium RC:- The next step is to download and configure Selenium RC. First, you need to go to the URL http://www.seleniumhq.org/download/ and download the latest version of the selenium server. Once that is done, the users need to command prompt and move to the JAR file folder. You will need to type the command ‘java -jar <<downloaded jar name >> to start the server.
  • Configure Selenium WebDriver- Lastly, you need to configure the selenium WebDriver by downloading it from http://www.seleniumhq.org/download/.

Learn Software Development Courses online from the World’s top Universities. Earn Executive PG Programs, Advanced Certificate Programs or Masters Programs to fast-track your career.

2. Selenium Commands:-

Commands are actions that a user enters for the Selenium tools to perform. There are three types of commands in Selenium – actions, accessors, and assertions.

a. Actions- These are commands used to manipulate or alter the situation of the application. Actions include:

  • Click (locator)- used to click on a link or button.
  • clickAt (locator, coordString)- uses locator or coordinates to click on an element.
  • close ()- allows the close option to appear as a popup window.
  • dragAndDropToObject (Dragobject, dropobject)- allows dragging an element and dropping it on another element.
  • contextMenuAt (locator, coordString)- used to open the context menu from a specified location.

b. Accessors:- Selenium accessors are used to check the application’s state, and the results are stored in variable form. Some of the most common accessors include:

  • storeAllButtons (variableName)- used to return the IDs of all buttons.
  • storeAllLinks (variableName) allows returning IDs of link pages.
  • storeConfirmation (variableName)- it is used to get the javascript confirmation message dialogue of the previous manuscripts.

c. Assertions:- The purpose of assertions is to verify the application’s state and do a comparison, if necessary.  Here are the most commonly used assertions for Selenium.

  • verifySelected (selectLocator, optionLocator) V- used to verify that the option specifier is satisfied by the selected option.
  • verifyAlert (pattern)- used to verify the alert text.
  • verifyAllLinks (pattern)- used to verify all links. People generally use this assertion with accessor storeAllLinks.

d. Locators:- The purpose of locators is to identify the HTML element and the command. The following are the different types of locators in commands.

  • identifier=id- used to select an element with ‘id’ or name attribute.
  • name=name- the first element with the name attribute is selected.
  • xpath=xpathExpression is used to locate an element using XPath expression.

Coverage of AWS, Microsoft Azure and GCP services

Certification8 Months
View Program

Job-Linked Program

Bootcamp36 Weeks
View Program

How to allow Selenium to interact with other apps?

The Selenium Webdriver allows the interaction of selenium with various web applications, which occurs through some basic-user defined functions and not predefined commands. The most common types of interactions in Selenium WebDriver are Text box interaction which requires putting values in a box and using the sand key method, Drop Down Item Selection, Keyboard Actions, Radio Button Selection, and more.

How to design tests in Selenium?

The primary purpose of using Selenium is to automate test checking. It can be done through different techniques like:

  • Page object model- Selenium has an inbuilt object repository, and it works through the different properties of its web elements like XPath and name. The path object model is used to create an object repository for Selenium which allows the formation of different web elements using class files. You need to follow these steps for testing:
  1. The first step requires creating a class through (page_objects_perc_calc.java). It is followed by creating methods for identifiers.
  2. Next, you have to create a class, import the package, and create methods for object identifiers.
  3. The test then gets executed. You will find it printed on the console.
  • Excel- To test a software product, it is necessary to parameterise a test initially. This can be done through Excel by following these steps:
  1. The first step is to download JAR Excel through the URL http://poi.apache.org/download.html.
  2. You need to unzip the earlier folder and create a new project.
  3. After that, you need to add all the external JARS in one folder by creating a new project.
  4. Next, you have to add ‘External JARs’  in ‘ooxml-lib’ and the ‘lib’ folder.
  5. Then you have to parameterise the inputs by using a % calculator in Excel.
  6. Create generic methods for accessing the Excel file and then the main method. Then execute the script.
  • Logging- This is done through Log4j, which is an audit framework.
  1. The first step is to download the log4j JAR file and create a new Java project.
  2. Add ‘log4j_demo’ to the name of the new project and click on the external jar.
  3. After this, you need to add Selenium WebDriver libraries and click on add JAR again to insert Selenium WebDriver JAR.
  4. Create a new XML file and add the properties of Log4j. Next, you must add a main function in the class file and execute it.
  • Multi-browser testing- With Selenium, you can simultaneously test and execute scripts in multiple browsers. You need to download and install Selenium Grid for this.
  • Capture screenshots or videos- This method allows taking screenshots of failure while the test is running. It is done through Selenium Grid with remote features. When a screenshot is not sufficient, you can also take videos to record the failure during program execution. Here is how you can capture videos.
  1. You must first download the screen recorder through      http://www.randelshofer.ch/monte/index.html.
  2. Then add the JAR file to the current project’s libraries.
  3. For graphics configuration, you can use Java’s AWT package.
  4. The recorded video is saved on your computer.

Conclusion

With increasing advancements in technology, organisations are focusing more on automation. Since Selenium is an automation software, deep knowledge of the framework will help you move forward in your career. You can get a job as an automation lead, quality engineer, and selenium automation analyst. 

If you are interested to learn the basics of Selenium and acquiring practical skills, check out upGrad’s PG Diploma in Full-stack Software Development course.

Frequently Asked Questions (FAQs)

1. What skills do I need to learn Selenium?

2. Is Selenium a good career option?

3. Is it necessary to know Java to learn Selenium?

Pavan Vadapalli

899 articles published

Get Free Consultation

+91

By submitting, I accept the T&C and
Privacy Policy

India’s #1 Tech University

Executive PG Certification in AI-Powered Full Stack Development

77%

seats filled

View Program

Top Resources

Recommended Programs

upGrad

AWS | upGrad KnowledgeHut

AWS Certified Solutions Architect - Associate Training (SAA-C03)

69 Cloud Lab Simulations

Certification

32-Hr Training by Dustin Brimberry

View Program
upGrad

Microsoft | upGrad KnowledgeHut

Microsoft Azure Data Engineering Certification

Access Digital Learning Library

Certification

45 Hrs Live Expert-Led Training

View Program
upGrad

upGrad KnowledgeHut

Professional Certificate Program in UI/UX Design & Design Thinking

#1 Course for UI/UX Designers

Bootcamp

3 Months

View Program