public void test01() {
List pageNum = getPageNum();
System.out.println(pageNum.size());
for (int j = 0; j < pageNum.size()-1; j++) {
List courseList = driver.findElements(By.className(“shizan-name”));
for (int i = 0; i < courseList.size(); i++) {
System.out.println(courseList.get(i).getText());
courseList.get(i).click();
sleep(500);
driver.navigate().back();
sleep(500);
courseList = driver.findElements(By.className(“shizan-name”));
}
driver.findElement(By.linkText(“下一页”)).click();
sleep(3000);
}
}
public List getPageNum() {
List pageNumList = new ArrayList();
List aElementList = driver.findElement(By.className(“page”)).findElements(By.tagName(“a”));
for (WebElement aElement : aElementList) {
String pageNum = aElement.getText();
if (isNum(pageNum) == true) {
pageNumList.add(Integer.valueOf(pageNum).intValue());
}
}
return pageNumList;
}
public boolean isNum(String pageNum) {
Pattern pattern = Pattern.compile("[0-9]*");
Matcher isNum = pattern.matcher(pageNum);
if (isNum.matches()) {
return true;
} else {
return false;
}
}
代码和上课的一样,但是实际执行的时候出现以下问题
这段代码循环完后,并没有跳到第7页就结束了,等于少了一页
而这段代码,我把-1删掉,执行完以后页码是对的,但是最后报了一个错,找不到linktest=“下一页”。这是怎么回事