Wednesday, 25 November 2015

Selenium WebDriver : Basic User Actions

Let us have a look at some basic user actions such as :

  1. Open Browser
  2. Open URL
  3. Sending data to Text Field
  4. Mouse Click
  5. Select Drop-down Option

Open Browser :

This is the first step towards writing Test Case Automation Script (for Web Applications). There are different ways to Open different browsers programmatically. Here we will discuss about three browsers : Mozilla Firefox, Internet Explorer, Google Chrome.

We need to download required Driver Servers before opening a Web Browser in Selenium WebDriver Script :

To download Driver Servers of other browsers, click here

Mozilla Firefox

If Selenium JARS version < 3.0 :

WebDriver driver = new FirefoxDriver();

If Selenium JARS version >= 3.0 :

File geckoDriver = new File("path to \\geckoDriverServer.exe"); System.setProperty("webdriver.gecko.driver", geckoDriver.getAbsolutePath() );
WebDriver driver = new FirefoxDriver();


Internet Explorer

File IEDriver = new File("path to \\IEDriverServer.exe");
System.setProperty("", IEDriver.getAbsolutePath() );
WebDriver driver = new InternetExplorerDriver();

Google Chrome
System.setProperty("", "path to \\chromedriver.exe");
WebDriver driver = new ChromeDriver();

WebDriver is the interface included in the Selenium JARs package. It contains various methods to perform different user actions.

Open URL :

Following line of code can be used to open a URL in any browser mentioned above :

driver.get(URL String);

Example :

This opens the required URL (or Website) in the browser initiated programmatically.

Sending data to Text Field :

This is one of the most frequently used User Action during Automation Script development. It is used while logging into a site, filling form data, etc.
Following line of code is used to fill data in a Text Field :


locator - This is the locator used to locate Web Element using one of the locating methods.
data - This is the String that we want to pass to the Text Field.

Mouse Click :

This is another frequently used User Action used to log in, Save form data, select drop-down option, etc.
Following line of code is used for a Mouse Click :


Here locator can be any Web Element such as a button, drop-down option or any element that a user can click.

Select Drop-down Option :

Selenium provides us with some inbuilt functions to select an option from drop-down menu.

Select option = new Select(driver.findElement(;
option.selectByVisibleText(Drop down Text);

option.selectByIndex(Index Value);
option.selectByValue(Value Attribute)

Example : Let us consider this HTML code snippet

<select id = "designation">
          <option value = "MD">MD</option>
          <option value = "prog"> Programmer </option>
          <option value = "CEO"> CEO </option>

To select Programmer, we can use any of the below methods :

Select option = new Select(driver.findElement(;


These are some of the User Actions used during Automation Script Development.

We will discuss about some advanced User Actions in upcoming posts.
Happy Learning.

YouTube Channel : Click Here

Tuesday, 24 November 2015

Getting Started - Selenium Project Set up in Eclipse

In this post, we will discuss about how to set up a Java Project in Eclipse and include required Selenium JAR files to develop Automation Test Cases.

For those who are not familiar with Eclipse, Click here

To create Project in Eclipse :

  • Click on File > New > Java Project.
    Enter "Project Name" and click on "Finish".

  • Configure the Project to include Selenium JAR files.
    Right Click on Project created > Build Path > Configure Build Path

  • Make sure that you have downloaded the latest JAR files (Download latest Selenium JAR files from here. I recommend to use latest Selenium JARS version with your updated browsers)
    Click on "Add External JARs" > Browse and select all JAR files > Click on "OK"

After following above mentioned steps, we are ready with required minimum configuration to use predefined Classes and Methods required for developing Automation Test Cases. There are several other JAR files required to perform different actions such as reading Excel / CSV file, generating custom reports, etc, which are not included in downloaded Selenium JARs package.
We will cover such scenarios one-by-one in upcoming posts.

We will discuss about automating basic user actions such as opening a browser, opening a URL, identifying and performing required actions with web elements, etc in the upcoming posts.
Happy Learning.

YouTube Channel : Click Here

Thursday, 11 June 2015

Selenium - Types Of Locators

In this post, lets discuss about various types of Locators available to locate Web Page Elements.
This is the most crucial part of automation since we start automating after locating required elements on the Web Page !!

Before trying out any of the examples below, make sure that you have JAVA and Eclipse installed on your machine.
Also download Selenium JARS (Click here)

Different Types of Locators include :

  • ID
  • Class Name
  • CSS
  • LinkText
  • Tag Name
  • Xpath
  • Name

These are the different methods used to locate Web Page elements.
Lets discuss each of them.

1 - Locating By ID :
          This is the first type of locator that we must use to locate an element (if ID of the required element exist). Since IDs are unique, we can find the required element easily by specifying its ID.
          <input id = "email" class = "required" type = "text" />
WebElement element = driver.findElement("email"));

If there is no ID for some particular desired element than we have to use other methods of locating elements.

2 - Locating By Class Name :
          Since multiple elements can belong to the same class, we have to ensure that the required element is located when using this method of locating elements. This is mostly used in conjunction with CSS for locating the right element. By default, it will return the first match it finds on the page.
          <input id = "email" class = "required" type = "text" />
WebElement element = driver.findElement(By.className("required"));

In this example, it finds the above tag but on actual sites you have to make sure that right element is found.

3 - Locating By CSS :
          This makes use of the DOM structure of the page and includes various combinations of other locators. Hence we will discuss about CSS method of locating elements in the next post.

4 - Locating By LinkText :
          This is used only when we want to find an element which is a link. We find it using the text of the link.
Example :
          <a href = ""> Google </a>
Webelement element = driver.findElement(By.linkText("Google"));

This way we can find the link that is displayed with the required text that we want to find. The element is found only when the link with desired text is present on the page.

5 - Locating By Tag Name :
          Another way of locating element is by using the tag name of the element. But like class names, we can have the same tag appear multiple times on the page. So care must be taken while using this approach.
Example :
          <p> This is a para </p>
WebElement element = driver.findElement(By.tagName("p"));

Again, make sure that the right element is found.

6 - Locating By Name :
          This makes use of the name attribute of the element to be found.
Example :
          <div id="pancakes">
                <button type="button" name="pancake" value="Blueberry">Blueberry</button>
                <button type="button" name="pancake" value="Banana">Banana</button>
                <button type="button" name="pancake" value="Strawberry">Strawberry</button>
WebElement element = driver.findElement("pancake"));

7 - Locating By Xpath :
          It is useful in case of cross browser testing since different browsers render CSS in different ways, hence using CSS selectors to locate elements would behave differently on different browsers.
To find Xpath - Right Click on the element and select "Copy Xpath".

To conclude, we have seen different types of locators that can be used to locate elements on a web page. The best way is to use ID or name of the element if they exist.

Will discuss about setting up of the project in Eclipse (integrating Selenium JARS) and CSS Selectors method of locating element in the upcoming post.
Happy Learning.

YouTube Channel : Click Here

Friday, 5 June 2015

Selenium IDE

Since this is the most basic tool in Selenium, we will see how it can be utilized to accomplish our automation tasks.
Anyone with or without any Programming Background can automate Web based applications using Selenium-IDE. It is a firefox add-on and you can install it easily from here.

This is how Selenium IDE looks like :

Selenium IDE provides different features such as Record and Playback, running single/multiple commands, running single/multiple Test Cases at a time, control the speed of execution of Test Cases, etc.

Lets have a look on different components of Selenium IDE :

  • Menu Bar - It contains various options such as creating/saving Test Cases/Test Suites, export to a particular language, insert/delete a command, saving in a particualar format, etc.
  • Base URL - This is where your test URL goes (the page that you are going to test).
  • Toolbar - It contains various components that helps in controlling the execution of Test Cases, running single Test Case or entire Test Suite, pause option, etc.
  • Test Case Pane - All the test cases are displayed in this section. Also displays the number of passed and failed Test Cases.
  • Editor - This is the section where all the commands, values and targets are entered automatically as we go through the page.

Some of the important Selenium IDE commands :
  • open - opens URL on current Web Browser instance
  • openWindow - opens URL on new Web Browser instance
  • click - clicks on an element
  • clickAndWait - clicks and wait for the page to load
  • store - used to store user defined values in a variable
  • echo - used to print data in Selenium IDE log section
  • storeText - used to store data from Web page in a variable
  • type - types a sequence of characters
  • verifyTitle - compares actual page title with expected page title
  • verifyText - compares the expected and actual values
  • verifyTextPresent - verifies presence of text on the page
  • verifyElementPresent - verifies presence of an element
  • assertText - compares the expected and actual values 
  • waitForPageToLoad - waits for the page to load
  • waitForElementPresent - waits for an element to be present
  • pause - pauses the execution of Test Script
  • refresh - refreshes the Web Page
  • storeLocation - stores the URL of a Web Page in a variable
  • storeTitle - stores title of a Web Page in a variable

The difference between "verify" and "assert" is :
Verify - The Test Case Execution continues even if the command fails.
Assert - The Test Case Execution stops if the command fails.

By default, Record button (small red circle on top right) is "on", hence the actions on web page are recorded automatically.
Most of the testers or developers use Selenium IDE to locate Web Elements. One can simply copy the identifier (using one of the identifying methods to be discussed) in "Target" field provided and click on "Find" to identify Web Element. If the required element is highlighted on the Web page, we can use the locator in "Target" field for that element in our Automation Script.

We will discuss about Selenium Webdriver and different types of locators(locating techniques) in the upcoming posts.
Happy Learning.

YouTube Channel : Click Here

References :

Thursday, 21 May 2015

Selenium Introduction

Selenium is a Software Testing Framework used to automate Web-based Applications. It is a collection of tools which can be used to perform various tasks.

Selenium is used to automate test cases related to Web Pages that are frozen and will not change in the near future. We can say that "Manual Testing" can be replaced by "Selenium (Automation)" to test most of the features on Web Pages.

Why To Automate ?

The first question that comes in our mind is: Why there is a need to automate Web-based Applications ? There are lots of things on a web page which requires our attention as far as testing is concerned, in order to deliver a perfect error-free optimized product. In such cases, it is difficult to track each and everything on a Website (presence of text boxes,functionality of buttons,etc).
For such reasons, Selenium was developed so that anyone with / without programming background can test for basic functionalities / UI elements and include such automated test cases in Sanity / Regression suites !! Even if you are not familiar with programming, don't worry, Selenium provides its hassle free "Record And Playback" feature via Selenium-IDE !!
Another reason is, Automation Scripts are not error prone when required to be executed multiple times, which allows us to use one of the Test Automation tool.

What To Automate ?

  • Functionalities that are not going to change in the near future.
  • Regression Testing.
  • Test Cases that takes more time to execute.
  • Test Cases that are error-prone and are very important.
  • Test Cases that require huge amount of input data.

What NOT To Automate ?

  • Functionalities that change frequently.
  • When a quick manual testing will do the job instead of Automation Script.
  • Testing the functionality for the first time.

Selenium Testing Framework - Various Tools:

Selenium IDE :

  • Very important tool for those who are not familiar with Programming.
  • Provides "Record and Playback" feature.
  • Contains various other features such as running a single/multiple test cases,test suites,controlling speed of execution,etc.
  • Its a Firefox Add-On.

Selenium RC :

  • It requires a standalone server for its execution
  • Needs a programming background.
  • Officially it has been deprecated so we will not go in detail.

Selenium Webdriver :

  • One of the most popular tool for Automation.
  • Programming background is needed.
  • Can automate almost any task on any Web Application.
  • Unlike Selenium RC, it doesn't require standalone server for its execution.

Selenium Grid :

  • Used to perform automation on remote machines.
  • Consist of one Hub and multiple Nodes.
  • Hub controls the execution of code on various Nodes.
  • This helps in parallel automation on different browsers and machines.

Will discuss these in upcoming posts.
Happy Learning.

YouTube Channel : Click Here