下面的代码停止在第2页运行,我有5到6页,每页包含10条记录......
public void pagenate() throws Exception {
page.findElement(By.xpath(".//[@id='leftnav-query-history']")).click();
List pagination = page.findElements(By.xpath(".//[@id='next']/a"));
System.out.println(pagination.size());
if(pagination.size()>0) {
System.out.println("pagination exists");
for(int i=0; i<pagination.size(); i++)
{
pagination.get(i).click();
page.findElements(By.xpath(".//*[@id='next']/a"));
}
}else {
System.out.println("pagination not exists");
}
}
答案 0 :(得分:-1)
请尝试以下代码:
public void pagenate(WebElement page) throws Exception {
page.findElement(By.xpath(".//[@id='leftnav-query-history']")).click();
do{
page.findElement(By.xpath(".//[@id='next']/a")).click();
Thread.sleep(1000);// You can Waitfor some element on next page to load or change, to improve performance.
} while (page.findElements(By.xpath(".//[@id='next']/a")).size()>0 && page.findElement(By.xpath(".//[@id='next']/a")).isDisplayed());
}