How to find total rows in a paginated web table ?

I am working on automating a .NET app using QTP 11.0. The app has a webtable which is paginated showing 30 rows per page.
How do I get the total row?

Showing Answers 1 - 9 of 9 Answers

harihar

  • May 9th, 2015
 

it is better to go with recording.... because some times developer use more hidden rows and columns for objects........with recording u came to know exact count of rows and columns in table..

  Was this answer useful?  Yes

Selenium can do this. May be this can help.

Code
  1. package readingTable;

  2.  

  3. import java.util.Iterator;

  4. import java.util.List;

  5.  

  6. import org.junit.After;

  7. import org.junit.Before;

  8. import org.junit.Test;

  9. import org.openqa.selenium.By;

  10. import org.openqa.selenium.WebDriver;

  11. import org.openqa.selenium.WebElement;

  12. import org.openqa.selenium.firefox.FirefoxDriver;

  13.  

  14. public class ReadingTableExample {

  15.         private WebDriver driver;

  16.         private String baseUrl="http://www.espncricinfo.com/";

  17.  

  18.         @Before

  19.         public void setUp() throws Exception {

  20.                 driver = new FirefoxDriver();

  21.                 driver.get(baseUrl);

  22.         }

  23.  

  24.         //Test to display how to read html table using webdriver on cricinfo.com.  

  25.         @Test

  26.         public void printFacebookFriendList() throws Exception {

  27.  

  28.                 //Get all the links for Scorecard.

  29.                 WebElement box = driver.findElement(By.cssSelector("div.ciHomeTopHeadlines"));

  30.                 List <WebElement> scorecard = box.findElements(By.linkText("Scorecard"));

  31.  

  32.                 //Click on the first scorecard link from News Section

  33.                 (scorecard.get(0)).click();

  34.  

  35.                 //Get all the data of the table

  36.                 WebElement table =

  37.                         driver.findElement(By.id("inningsBat1"));

  38.                 List<WebElement> rows = table.findElements(By.tagName("tr"));

  39.                 Iterator<WebElement> i = rows.iterator();

  40.  

  41.                 //Print the table.

  42.                 while(i.hasNext()) {

  43.                         WebElement row = i.next();

  44.                         List<WebElement> columns = row.findElements(By.tagName("td"));

  45.                         Iterator<WebElement> j = columns.iterator();

  46.  

  47.                         while(j.hasNext()) {

  48.                                 WebElement column = j.next();

  49.                                 //Removing blank columns data and add a separator while displaying data.

  50.                                 if (!column.getText().trim().equals("")){

  51.                                         System.out.print(column.getText());

  52.                                         System.out.print(" | ");

  53.                                 }

  54.                         }

  55.                         System.out.println("");

  56.                         System.out.println("-----------------------------------------------");

  57.                 }

  58.         }

  59.  

  60.         @After

  61.         public void tearDown() throws Exception {

  62.                 driver.quit();

  63.         }

  64. }

  Was this answer useful?  Yes

sourabh

  • Nov 19th, 2017
 

Get Matching Xpath Count Use this keyword in Robot

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions