I have a page where the number of rows are present and it is dynamic. I want to verify the text which is showing 1 to 18 rows are showing. But it should not be hard coded. It should return the actual number of rows present.
-
1If you are actually hoping to get an answer, then I strongly recommend that you add the following: 1. The code that you have implemented so far. 2. The language that you are using (if not obvious from your code). 3. The URL of the web-page that you are trying to access, or at least the relevant piece of HTML within that web-page. – barak manos Mar 05 '14 at 12:20
3 Answers
Since you have mentioned language i giving you a example in C# you do the following
IWebElement location = Browser.Driver.FindElement(table locator));
ReadOnlyCollection<IWebElement> totalRow = location.FindElements(By.TagName("tr"));
will give the number of rows present
totalRowtotalRow.Count;
If you some more help let me know

- 760
- 5
- 13
- 28
Here is a similar example using Java:
int rowCount = 0;
rowCount = driver.findElements(By.xpath("//table/tr").size();
System.out.println("number of rows: "+rowCount);

- 1,821
- 2
- 18
- 14
First you should grab the WebElement that displays the count of showing 1 to 18 rows and try capturing the numbers from the string using regex and store it in a variable.
For extracting numbers, you can refer - https://stackoverflow.com/a/2367418/2482430
Later you can find all available elements based on suitable XPath or CSS Locator as below
List<WebElement> elements = driver.findElements(By.xpath("//table//tr"));
or
List<WebElement> elements = driver.findElements(By.cssLocator("table tr"));
Finally you can do the Assert as below,
Assert.assertTrue(elements.size() == totalRowsCount);