Handling Dynamic Web Tables Using Selenium WebDriver
There are two types of HTML tables published on the web-
- Static tables: Data is static i.e. Number of rows and columns are fixed.
- Dynamic tables: Data is dynamic i.e. Number of rows and columns are NOT
- fixed.Handling static table is easy, but dynamic table is a little bit difficult as rows and columns are not constant.
Using X-Path to Locate Web Table Elements
Before we locate web element, first let's understands-
What is a web element?
Web elements are nothing but HTML elements like textbox, dropdowns radio buttons, submit buttons, etc. These HTML elements are written with start tag and ends with an end tag.
For Example,
<p> My First HTML Document</p>.
Steps for getting X-path of web element that we want to locate.
Step 1) In Chrome, Go to http://money.rediff.com/gainers/bsc/daily/groupa

Step 2) Right click on web element whose x-path is to be fetched. In our case, right click on "Company" Select Inspect option. The following screen will be shown -

Step 3) Right Click on highlighted web element > Select Copy -> Copy x-path option.

Step 4) Use the copied X-path "//*[@id="leftcontainer"]/table/thead/tr/th [1]" in Selenium WebDriver to locate the element.
Example: Fetch number of rows and columns from Dynamic WebTable
When the table is dynamic in nature, we cannot predict its number of rows and columns.
Using Selenium web driver, we can find
- Number of Rows and columns of web table
- X row or Y column's data.
Below is program for fetching total number of rows and columns of web table
![]() |
ScreenShotimport java.text.ParseException; import java.util.List; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.chrome.ChromeDriver; public class Noofrowsandcols { public static void main(string[] args) throws ParseException { WebDriver wd; System.setProperty("webdriver.chrome.driver", "D:\\ chromedriver.exe") ; wd = new ChromeDriver(); wd.get("http://money.rediff.com/gainers/bsc/dailygroupa?"); //No.of Columns List <WebElement> col = wd.findElements(By.xpath(".//*@id="leftcontainer']/table/thead/tr/th")); System.out.println("No of cols are : " +col.size()); //No.of rows List <WebElement> rows = wd.findElements(By.xpath(".//*[@id="leftcontainer']/table/tbody/tr/td[1]")); System.out.println("No of rows are : " + rows.size()); wd.close(); }
.Output:
Example: Fetch cell value of a particular row and column of the Dynamic Table![]() |
Wonderful Blog on recent updates, I have updated my knowledge through your blog, Thanks admin for sharing the recent information.
ReplyDeletetesting training chennai
Software testing institutes in chennai
ReplyDeleteGreat thoughts you got there, believe I may possibly try just some of it throughout my daily life.
rpa Training in Chennai
rpa Training in bangalore
rpa Training in pune
blueprism Training in Chennai
blueprism Training in bangalore
blueprism Training in pune
iot-training-in-chennai
It's interesting that many of the bloggers to helped clarify a few things for me as well as giving.Most of ideas can be nice content.The people to give them a good shake to get your point and across the command
ReplyDeleterpa online training
automation anywhere training in chennai
automation anywhere training in bangalore
automation anywhere training in pune
automation anywhere online training
blueprism online training
rpa Training in sholinganallur
rpa Training in annanagar
blueprism-training-in-pune
automation-anywhere-training-in-pune
Really you have done great job,There are may person searching about that now they will find enough resources by your post
ReplyDeleteData Science Training in Chennai
Data science training in bangalore
Data science online training
Data science training in pune
Data Science training in kalyan nagar
Data Science training in OMR
selenium training in chennai
Thanks
DeleteI have visited this blog first time and i got a lot of informative data from here which is quiet helpful for me indeed.
ReplyDeletejava training in tambaram | java training in velachery
java training in omr | oracle training in chennai
java training in annanagar | java training in chennai
Thank you for this post. Thats all I are able to say. You most absolutely have built this blog website into something speciel. You clearly know what you are working on, youve insured so many corners.thanks
ReplyDeletepython training in pune
python online training
python training in OMR
Thanks for splitting your comprehension with us. It’s really useful to me & I hope it helps the people who in need of this vital information.
ReplyDeleteBlueprism training institute in Chennai
Blueprism online training
Blue Prism Training Course in Pune
Blue Prism Training Institute in Bangalore
Great Article… I love to read your articles because your writing style is too good, its is very very helpful for all of us and I never get bored while reading your article because, they are becomes a more and more interesting from the starting lines until the end.
ReplyDeleteangularjs-Training in sholinganallur
angularjs-Training in velachery
angularjs Training in bangalore
angularjs Training in bangalore
angularjs Training in btm
Greetings. I know this is somewhat off-topic, but I was wondering if you knew where I could get a captcha plugin for my comment form? I’m using the same blog platform like yours, and I’m having difficulty finding one? Thanks a lot.
ReplyDeleteAWS Interview Questions And Answers
AWS Online Training | Online AWS Certification Course - Gangboard
AWS Training in Chennai | AWS Training Institute in Chennai Velachery, Tambaram, OMR
AWS Training in Bangalore |Best AWS Training Institute in BTM ,Marathahalli
Nice Blog Thank you for sharing..
ReplyDeleteReally nice and interesting.Automation Anywhere Training in Bangalore
Good blog....
ReplyDeleteInformatica message Queue training
Informatica power center training
Manual Testing training
Open stack training
That was perfect, valuable thoughts, thanks for sharing your knowledge
ReplyDeleteWordpress Training in Chennai
Wordpress Training Institutes in Chennai
Good blog!!! it was more informative.
ReplyDeleteHow to Become a Social Media Manager?
How to Become Social Media Manager?