Selenium Tutorials

By | August 4, 2020

Selenium Tutorials Introduction:

Selenium is a free and open source test automation tool for testing web applications.

Selenium can be installed on most of the operating systems like

  • Windows 
  • Linux 
  • Apple iOS   etc.

Cross browser testing is possible using selenium i.e., we can run the test scripts in different browsers like

  • Firefox 
  • IE 
  • Chrome 
  • Opera 
  • Safari  etc.

Selenium is a suite of tools having various testing functions used to test all types of web applications. One of the key features in selenium is “Multi browser testing“. Selenium supports below programming languages:

  • Java
  • C++
  • Python
  • Pearl
  • PHP
  • Ruby

In this selenium tutorial you will learn about selenium framework, TestNG reporting, locators to identify web elements, interview questions and selenium quiz.

Pre-requisites to learn selenium:

Selenium Tutorials 1

Selenium WebDriver:

WebDriver API is a new feature that has been added in Selenium 2.0. The main purpose of Webdriver is to provide a simple programming interface and to overcome the limitations faced in the Selenium RC API.

Setup Selenium WebDriver project:

We need any of the below java development IDE’s to work on Selenium. Prior to this, we need to download Selenium Standalone Server from

Extract the zip file to a folder. It contains the required jars to run selenium scripts.

Setup Java SE Development Kit:

Download and install the Java SDK from –

Setup Eclipse:

Download Eclipse IDE from –

Setup TestNG:

Can be installed via two methods.

  • From Eclipse Marketplace.
  • From update site.

How to use WebDriver API:

We have to create a Web Driver instance and instantiate the driver to any particular browser.


WebDriver wd=new FirefoxDriver();

Internet Explorer:

WebDriver wd=new InternetExplorerDriver();

Google Chrome:

WebDriver wd=new ChromeDriver();


WebDriver wd=new SafariDriver();


WebDriver wd=new OperaDriver();


How to locate web elements in the UI:

First, we need to identify the elements/objects present in the DOM to do any action. The element is maybe a textbox, textarea, dropdown, radio button, checkbox, or text present in the UI. A web element can be identified using below locators.

In the above code, WebElement is used to store the element present in the DOM, findElement() method is used to locate the element in the DOM. By() method is having different identifiers to locate the element.

  • By ID
  • By Xpath
  • By Linktext
  • By CssSelector
  • By Name



Sample WebDriver script having usage of all the locators:


Difference between findElement() and findElements() method:

*findElement() method returns only one web element. If the element does not found in the DOM, it throws NoSuchElementException.

*findElements() method returns zero or more web elements in the form of list. If element is not found in the DOM, it returns an empty list. If one or more elements with same identifying criteria found, then it returns all elements in the form of list.


import java.util.List;

List<WebElement> list=driver.findElements(By.tagName(“a”));


Firebug and Firepath:

These are the Firefox plugins or add-ons used to inspect the HTML elements. 


Inspecting the web element:

To verify whether Firebug is installed, check for the Firebug icon in the top right corner of the browser. To inspect any web element, click on the Inspect Element icon and move the cursor to the respective HTML element. Firebug highlights the HTML code of the web element or displays the xpath of the element in the XPath bar.

Selenium Tutorials 2


How to work with different web elements (Hands on):

Select a dropdown using selenium webdriver.

Tags: Selenium tutorials, selenium framework







Recommended Posts:

Convert string to int in Java
StringUtils methods
How to take screenshot in Selenium

Leave a Reply

Your email address will not be published. Required fields are marked *