Hey there! any question in your mind? Ask It Now!.

Popular Categories





How to get a table content from Web page through Selenium Web driver?

+1 vote
2,018 views
asked in Software Testing by CaptSaltyJack (1,140 points)
I have a web page which comes with dynamic contents in table and tables <tr> is not fixed it changes every time so how can I get this table content through WebDriver in selenium?
 
thanks for helping!

1 Answer

+1 vote
answered by seleniumGuru Expert (4,570 points)
selected by CaptSaltyJack
 
Best answer
In the same way you can use this ,Here we are counting number of tr in a table then ,in loop we are printing on by one all tr data ,you can store in array and can use accordingly your need.
 
 int size = driver.findElements(By.xpath("//*[@id='demo_ID']/tbody/tr")).size();
 
  NOTE : here you need to use findElemets not findElemet .
  
  for(int i=1;i<=size;i++){
  
  WebElement text =  driver.findElement(By.xpath("//*[@id='demo_ID']/ul/tbody/tr["+i+"]/a"));
  
  String strGetContent = text.getText();
  System.out.println(strGetContent);
}
So by this you can store or get table content from Web page through Selenium Web driver.
Enjoy!
commented by tester (1,550 points)
hey @Selenium Guru good job man , I was working on a page, Which is containing dynamic data like my web page was coming with available products and products are coming from DB (DataBase) I was facing problem because these were not fixed so then I used this code to autamate that page, My scenario was varifing the correct product on the web page, and its done . Thanks for such a nice example.

Related Questions

+1 vote
1 answer 539 views
+1 vote
1 answer 2,348 views

Not a Member yet?

Ask to Folks Login

My Account
335 Folks are online
27 members and 308 guest online
Your feedback is highly appreciated