在表中应用分页后如何使用Selenium验证行数?

时间:2019-03-27 13:40:55

标签: java selenium selenium-webdriver automated-tests

我正在尝试用硒编写一个测试用例,其中我必须将分页设置为10,并确认设置分页后显示的记录数也是10。但是无论如何,我最终给出的值都等于1。但是我应该得到的答案是10。

enter image description here

我尝试针对表ID使用size()函数。但是最终得到的值为1。

String ExpectedNumberOfRecordsBasedOnPagination="10";
Pagination.selectByVisibleText(ExpectedNumberOfRecordsBasedOnPagination);

WebElement VehicleNumberTable=driver.findElement(By.xpath("//table[@id='tableforsearchResultsEMI']/tbody"));
List<WebElement>ListOfRecordsBasedOnPagination=VehicleNumberTable.findElements(By.tagName("tr"));
int ActualNumberOfRecordsBasedOnPagination=ListOfRecordsBasedOnPagination.size();
System.out.println("Scenario 10 Pass: When the user sets the Pagination to a certain number: "+ExpectedNumberOfRecordsBasedOnPagination 
    +" Then the table values should display the same number of records:" +ActualNumberOfRecordsBasedOnPagination );

期望值为10,但我得到1。

2 个答案:

答案 0 :(得分:0)

感谢大家的投入。 我在分页功能和计数行功能之间添加了 thread.sleep()后,它起作用了

答案 1 :(得分:0)

  • 代替Thread.sleep(),更好的方法是等待 label(“ 1 of 10”),然后验证行数。