Wednesday, February 22, 2017

How To Handle Dynamic Web Table In Selenium WebDriver

In this selenium webdriver post, we will learn how to handle dynamic web table. There might occur some scenarios where every time a page loads with different number of rows and columns or different columns for each row.

For that, we have to put two for loops,
1. first loop will iterate all the rows and
2. second loop inside it will iterate the columns of each row

import java.util.List;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
public class DynamicTable {
WebDriver driver = new FirefoxDriver();
public void setup() throws Exception {
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
public void tearDown() throws Exception {
public void Handle_Dynamic_Webtable() {
//To locate table.
WebElement mytable = driver.findElement(By.xpath(".//*[@id='post-body-8228718889842861683']/div[1]/table/tbody"));
//To locate rows of table.
List rows_table = mytable.findElements(By.tagName("tr"));
//To calculate no of rows In table.
int rows_count = rows_table.size();
//Loop will execute till the last row of table.
for (int row=0; row
//To locate columns(cells) of that specific row.
List Columns_row = rows_table.get(row).findElements(By.tagName("td"));
//To calculate no of columns(cells) In that specific row.
int columns_count = Columns_row.size();
System.out.println("Number of cells In Row "+row+" are "+columns_count);
//Loop will execute till the last cell of that specific row.
for (int column=0; column
//To retrieve text from that specific cell.
String celtext = Columns_row.get(column).getText();
System.out.println("Cell Value Of row number "+row+" and column number "+column+" Is "+celtext);

Feel free to ask queries. Happy Coding :)

Vaneesh Behl

Monday, February 20, 2017

How To Extract Table Data/Read Table Data Using Selenium WebDriver

Following Script will extract table data:

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

public class table { 
 WebDriver driver = new FirefoxDriver();
    public void setup() throws Exception { 
         driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
 public void tearDown() throws Exception { 
 public void print_data(){
 //Get number of rows In table.
 int Row_count = driver.findElements(By.xpath("//*[@id='post-body-6522850981930750493']/div[1]/table/tbody/tr")).size();
 System.out.println("Number Of Rows = "+Row_count);
 //Get number of columns In table.
 int Col_count = driver.findElements(By.xpath("//*[@id='post-body-6522850981930750493']/div[1]/table/tbody/tr[1]/td")).size();
 System.out.println("Number Of Columns = "+Col_count);
 //divided xpath In three parts to pass Row_count and Col_count values.
 String first_part = "//*[@id='post-body-6522850981930750493']/div[1]/table/tbody/tr[";
 String second_part = "]/td[";
 String third_part = "]";
 //Used for loop for number of rows.
 for (int i=1; i<=Row_count; i++){
  //Used for loop for number of columns.
  for(int j=1; j<=Col_count; j++){
   //Prepared final xpath of specific cell as per values of i and j.
   String final_xpath = first_part+i+second_part+j+third_part;
   //Will retrieve value from located cell and print It.
   String Table_data = driver.findElement(By.xpath(final_xpath)).getText();
   System.out.print(Table_data +"  ");   

Console output of above given example will looks like bellow.
Number Of Rows = 3
Number Of Columns = 6
11  12  13  14  15  16  

21  22  23  24  25  26  

31  32  33  34  35  36

Tuesday, February 7, 2017

Handling Multiple Browser Tabs Using Selenium Webdriver

We can perform a number of actions by combining third party things along with Webdriver, which webdriver is not capable if doing it alone. In this context sharing with you a program of handling multiple tabs. We can make use of Key controls which Robot api of java provides, to handle multiple tabs.

import java.util.concurrent.TimeUnit;  
 import org.openqa.selenium.By;  
 import org.openqa.selenium.Keys;  
 import org.openqa.selenium.WebDriver;  
 import org.openqa.selenium.firefox.FirefoxDriver;  
 public class Switchbetweenbrowsertab {  
   public static void main(String[] a) throws InterruptedException {  
     // Initialize driver  
     WebDriver driver = new FirefoxDriver();  
     //Maximize browser window   
     //Go to URL  
     //Set timeout  
 driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);  
     // Open new tab  
 driver.findElement(By.cssSelector("body")).sendKeys(Keys.CONTROL + "t");  
     //Go to URL  
     //Set new tab timeout  
  driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);  
     // Do some operation      
     // Switch first tab  
 driver.findElement(By.cssSelector("body")).sendKeys(Keys.CONTROL + "\t");  
     // Write search String  
     // Click on Search button      
     // Browser close   

Feel free to share your views/queries. Happy Learning :)

@uthor  Vaneesh Behl

Thursday, September 22, 2016

Code Resuablity & Maintainablility Using Action Methods in Selenium Webdriver

In this post I'm going to share kind of coding pattern which is very helpful in maintaining our automation code. This post is written insight to help beginners. We'll learn that instead of writing a linear script, we should create action methods (functions) which in general contain actions which we are going to performing on our web software.

Let's say, we have a login functionality in our software and we have to automate it. In that case we'll create a method named login and write the commands like, entering username, password and click login in that method. Now we can use that method wherever we need it in other test cases as well. Benefits of using action methods are:

  • Code Reusability
  • Better maintainability of code
Sharing below a sample script, in which I'm entering data in a web form using action methods:

Feel free to ask queries. Happy Coding :)

Vaneesh Behl

Tuesday, August 2, 2016

TECHLISTICSPACE  covers Automation Testing & Tools, Mobile Automation, Selenium Webdriver, Sikuli, Robot Framework, Appium, Java, TestNG, JUNIT, JENKINS, Automation Frameworks etc.

Blog Sections:


Appium For Mobile Automation

 Selenium Webdriver
                            Sikuli - An Image Based Automation Tool      

Java Stuff                                           Robot Framework

More Stuff                           TestNG

Tuesday, July 19, 2016

Selenium Essentials - Become Expert in Selenium Automation

Folks, I thought of sharing Selenium Essentials which you must cover if you want to get expertise in Selenium Automation. It might help beginners and intermediate techies. I have divided the content in to two parts, Basic and Advanced. And I have linked the content to other web links of the blog, and planning to cover all in my future blog posts, and link all the contents periodically. Find below the Selenium Essentials:

Course is divided into two Parts:

PART 1 - Basic Selenium which teaches you about Selenium IDE – Record and Play, Debug, Verification points and XPATH.

PART 2 - Advanced Selenium using Java which teaches Java/JUnit, Eclipse IDE, Selenium RC, Data Driven Testing, Ajax based application Testing.

1) Manual Testing Concepts
2) Software Development Life Cycle
3) Automation
3.1 Introduction to Automation
3.2 Test Automation of Web Application


1) Selenium Overview
2) Introduction to Selenium
3) Selenium IDE Basics
3.1 Getting Started

4) Selenium IDE
4.1 Introduction of Selenium IDE
4.2 Installing Selenium IDE
4.3 Starting Selenium IDE 
4.4 Selenium IDE Commands 
4.5 Writing Sample Test Case 
4.6 Running Selenium Tests on Different browsers

5) Tools for Writing Test Cases
5.1 Introduction
5.2 Overview and Usage of tools.
6) XPATH & Regular Expressions
6.1 Introduction to XPATH
6.2 Tools (Firebug & Firepath)

7.1 Recording and Running
7.2 Editing and Debugging.
7.3 Verifying Page Elements – Assertions and Verifications.
7.4 Locating Elements
7.5 Matching Text Patterns.
7.6 Store Commands and Selenium Variables
7.7 JavaScript and Selenese Parameters
7.8 Handling Alerts, Popup and Multiple Windows.


1) Selenium Webdriver
1.1 Webdriver Architecture

2) Eclipse
2.1 Installing Eclipse
2.2 About Eclipse IDE
2.3 Preparing Eclipse
2.4 Java Project (Classes, JUnit Classes) Editors, View and Perspectives
2.5 Simple Project 
2.6 Importing and Exporting
2.7 Eclipse Features
2.8 Debugging using Eclipse
2.9 Installing Eclipse Plug-in

3) Junit


About JUnit.
Test Fixture.
Sample JUnit Test Cases.
Test Runners.
Working with Test Case.
Working with Test Suites.
Testing Exception Handling.
Exercises and Examples.
JUnit 4

4) TestNG             
4.1 Annotations - @BeforeClass, @BeforeTest, @BeforeMethod, @Test 
4.2 Annotations - @AfterClass, @AfterTest, @AfterMethod
            4.4 Priority
            4.5 testNG.xml
            4.6 Groups          

Feel free to share your views/queries. Happy Learning :)

Vaneesh Behl

Friday, July 15, 2016

Mobile IOS Automation Part 1 - Appium Configuration with MAC

In recent days I got the chance to work on a Mobile Automation assignment. I got enough time for hands-on. I didn't have much experience on mobile automation before. I thought of sharing installation steps for Appium on MAC. I pen down all the configuration details and sharing below, so others could take help from it:

MAC Configuration with Appium

List of downloads:-
1.        Download Appium version 1.XX (.dmg) file      from
2.        Download Appium-master from
3.        Download latest android sdk.
4.        Install latest Xcode
5.        Update Android sdk with
a)        Latest API level
b)        Android SDK Build tools, SDK tools and SDK platform-tools from tools
c)        Google USB driver and Google Web-driver from extras.
6.        Download safari-launcher from for mobile web testing in iPhone.

Environment variables : -
1.    Open terminal
2.    vi .bash_profile 
3.    press 'i' and  enter these export commands
a)              export ANDROID_HOME=android sdk path
b)              export PATH=$ANDROID_HOME/platform-tools:$ANDROID_HOME/tools:$PATH
c)              press Esc key.
4.    ‘Shift’ + ’:’
5.    wq > enter
6.    re open terminal.

Installing IOS_Web_PROXY
1.      open terminal and enter these commands
 > ruby -e "$(curl -fsSL"
 > brew update
 > brew install ios-webkit-debug-proxy

Installing safari-launcher in iPhone
l  Require Apple account linked with developer program
l  Add device to developer program
l  Launch the on connected device from Xcode.

Pre-Script Steps In terminal
·         ios_webkit_debug_proxy
·         cd
·         ./bin/ios-webkit-debug-proxy-launcher.js -c:27753

Configuring Appium from its source code
l  npm install appium@1.4.16
l  Run this bin/appium-doctor.js from installed appium folder
l  Copy .git folder from cloned appium (git clone
l  Navigate to appium folder and execute ./
l  Provide path of installed appium source code in “Use External Appium Package” in appium UI under Developer setting.
l  Troubleshooting
n  If error related to ideviceintaller :- Execute brew install --HEAD ideviceinstaller  

n  If error related to provisional profile :- Execute ./ --ios --ios-safari after navigating to installed appium folder.

Vaneesh Behl