我使用下面的代码进行分页,第二页可以点击但下一页无法点击
List<WebElement> pagination = driver.findElements(By.tagName("i"));
List<WebElement> pagination1 = driver.findElements(By.xpath(".//[@id='ctl00_cpHFooter_PageUC1_rptrPager_ctl05_lnkNext']/i"));
pagination.size();
System.out.println("Total pages :" + pagination.size());
if(pagination .size()>0)
{
System.out.println("pagination exists");
//click on pagination link
for(int i=0; i<pagination1.size(); i++)
{
pagination1.get(i).click();
JavascriptExecutor jse1 = (JavascriptExecutor)driver;
jse1.executeScript("scroll(0, 2000);");
}
}
else
{
System.out.println("pagination not exists");
}
答案 0 :(得分:0)
您必须从第2页开始并使用一些等待或sleep()
List<WebElement> pagination = driver.findElements(By.tagName("i"));
List<WebElement> pagination1 = driver.findElements(By.xpath(".//[@id='ctl00_cpHFooter_PageUC1_rptrPager_ctl05_lnkNext']/i"));
pagination.size();
System.out.println("Total pages :" + pagination.size());
if(pagination .size()>0)
{
System.out.println("pagination exists");
//click on pagination link
for(int i=2; i<pagination1.size(); i++)
{
pagination1.get(i).click();
Thread.sleep(5000);
JavascriptExecutor jse1 = (JavascriptExecutor)driver;
jse1.executeScript("scroll(0, 2000);");
}
}
else
{
System.out.println("pagination not exists");
}