+1 vote
in Software Testing by (630 points)
edited by
I am trying to automate a page in which row comes dynamically, i mean some time the page is containing 3 rows some times 9 rows.
Is there any way so that i can count available rows or tr in tables or div So that i can put condition after counting the rows by xpath , if you have any idea so please let me know with a example.
Thanks in advance! 

1 Answer

+1 vote
by Expert (4.6k points)
selected by
Best answer
Nice Question , For this situation we will count the avalable row in web page, Lets see a example of <ul> and <li>
here li are dynamic see this example.  
 int size = driver.findElements(By.xpath("//*[@id='demo_ID']/ul/li")).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/li["+i+"]/div[4]/p[3]/span[1]"));
  String strGetContent = text.getText();
Here we will get the all available row's content in web page, I hope you got my point , if you have any problem so let me know.
by (630 points)
Thanks Sir , I got your point its a very nice way to deal with dynamic pages.

Not a Member yet?

Ask to Folks Login

My Account

Your feedback is highly appreciated