i
WebDriver Introduction
Selenium WebDriver Architecture
Introduction to WebDriver API
Introduction to WebDriver – Code
Handling Dropdowns and Select class
Handling Multiple Dropdown values and Links
Handling Radio buttons and Checkboxes
Capture Screenshots and Email test results
Browser Navigation Methods
Handling tabs
Capturing screenshot, Handling tabs and pop-ups – Code
Handling tabs and Pop-ups – Code
Handling Alerts
Handling User Authentication and Input alerts
HtmlUnitDriver and Handling Captchas
Handling Web Tables
Synchronization
Handling WebTables, Synchronization issues, Firefoxprofiles – Code
Actions Class
Event Listeners, Event Firing Mouse, Coordinates – Code
Handling Mouse Hover in Selenium
JavascriptExecutor
Handling Iframes
IsElementPresent, IsEnabled, IsSelected
Working with Chrome Driver - Part 1
Working with FireFox Driver - Part 2
Working with Internet Explorer Driver - Part 3
Handling SSL Certificate
Desired Capabilities
How to Encode password in WebDriver
Handling JQuery Elements - Drag and Drop, Sliders, Resizable
Handling JQuery Elements - Drag and Drop, Sliders, Resizable – Code
Working on IE Browser using Actions
TestNG, Ant & Report Generation through XSLT
Introduction to TestNG and Annotations
TestNG Parameterization
Configuring ANT, Generating TestNG & XSLT Reports
Code for generating XSLT / Surefire Reports through MAVEN
TestNG Parameterization Excel Reading
Handling Multiple data providers
TestNG XSLT Jar, Build.xml & TestNG.xml file
Frameworks Introduction
Hybrid (DATA + KEYWORD) driven Framework
Framework Architecture
Reading Excel sheets
TestNG DataProvider
Data Provider with Hashtable
Handling Multiple Test Suites
Multiple DataProviders
Setting up Run-modes at Suite Level
Setting up Runmodes at TestCase Level
Creating a common utility for Run-modes
Hybrid Framework Code
Identifying HTML Table
First, we need to identify the web tables in the HTML source code. Whenever we see a table structure in a web page, it is surrounded by a tag. If we look inside the table tag, we can see and and
tags as well. | |
tags represent the row and column of the table respectively. Headings in a web table is tagged by | tag.
Now we should be able to understand the HTML tables of a web page. Let us roam around the Precise Testing Solutions official web page www.precisetestingsolution.com/functional-automation-testing.php to find an excellent example on web tables.
Now if we click on the inspect element on the web browser, we get the HTML source code of this web table as below:
Locating the web table cell and fetching the cell text Suppose we need to find the second row and the first column, i.e., "Functional Testing” text. First, we need to check the absolute Xpath of this text. Let’s figure out the web element using the Xpath for this text from the web page. WebElement element2=driver.findElement(By.xpath("/html/body/div[1]/div[3]/div[2]/div/div[1]/table/tbody/tr[2]/td[1]")); Now we can simply use the getText() method to get the text out of the element which is nothing but “Functional Testing” text. String sText=element.getText(); Dynamic rows and columns: Let’s make it more dynamic by assigning the variables to row and columns. String sRow=”2”; String sCol=”1”; This time row and column tags will be replaced by dynamic variables sRow and sCol. WebElement element2=driver.findElement(By.xpath("/html/body/div[1]/div[3]/div[2]/div/div[1]/table/tbody/tr["+sRow+"]/td["+sCol+"]")); Now it has become more dynamic in nature that we have made the row and column tags dynamic. Using this approach we can locate any element in web table and also text of the element can be fetched using getText() method. String eleText=element2.getText(); System.out.println(eleText); Console Output: Output text will be “Functional Testing” at console.
Finding a text-based cell in a web table: In some cases, the table is large enough to look for a cell, and we want to do a dynamic search that looks for a cell element by a text. Suppose we want to find the "JMeter" cell element in the web table. Here we need to look at each cell containing the text "JMeter," and once it matches the same, we can get the element of the cell as well. public class App { public static void main( String[] args ) { System.setProperty("webdriver.chrome.driver","C:\\Users\\chromedriver.exe"); WebDriver driver=new ChromeDriver(); driver.get("https://www.precisetestingsolution.com/functional-automation-testing.php"); String givenText="JMeter"; // Let us assign a string variable to collect the cell texts String eleText=""; //Nested for loops to check each cell until the expected one is matched. for(int i=2; i<=7;i++) { for(int j=1;j<=3;j++) { WebElement element2=driver.findElement(By.xpath("/html/body/div[1]/div[3]/div[2]/div/div[1]/table/tbody/tr["+i+"]/td["+j+"]")); eleText=element2.getText(); if(eleText.contains(givenText)) { System.out.println("Expected Element is located and is: "+eleText); }
} }
driver.quit(); } } |
---|
Don't miss out!