+1 vote
2.4k views
in Software Testing by (1.1k 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!
closed

1 Answer

+1 vote
by Expert (4.6k points)
selected by
 
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!
by (1.6k 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.

Not a Member yet?

Ask to Folks Login

My Account

Your feedback is highly appreciated