WebElement Table = driver.findElement(By.xpath("//body[@leftmargin='0']/form[@id='Form1']/table[@cellspacing='0']/tbody/tr[@valign='top']/td[@valign='top']/table/tbody/tr/td[@valign='top']/table[@id='tblReview']/tbody/tr[4]/td[1]"));
WebElement page = driver.findElement(By.xpath("//td[@colspan='11']//table[@border='0']"));
List<WebElement> allpages = page.findElements(By.tagName("a"));
for(int k = 2; k<= allpages.size();k++){
List<WebElement> rows = Table.findElements(By.tagName("tr"));
for(int i = 2; i< rows.size()-3; i++){
List<WebElement>columns = rows.get(i).findElements(By.tagName("td"));
sb = new StringBuilder();
for(int j = 1; j<= columns.size()-5; j++){
if(j == 1){
Thread.sleep(2000);
WebElement MsId = columns.get(j).findElement(By.xpath("//table[1]/tbody[1]/tr["+i+"]/td["+j+"]/a[1]"));
Thread.sleep(2000);
WebElement ReviewTitle = columns.get(j).findElement(By.xpath("//table[1]/tbody[1]/tr["+i+"]/td["+j+"]/a[2]"));
Thread.sleep(2000);
WebElement ReviewKey = columns.get(j).findElement(By.xpath("//table[1]/tbody[1]/tr["+i+"]/td["+j+"]/span[2]"));
sb.append(MsId.getText());
sb.append(ReviewTitle.getText());
sb.append(ReviewKey.getText());
} else if(j == 2) {
sb.append(columns.get(j).getText());
} else if (j==4){
sb.append(columns.get(j).getText());
}else if(j==5){
sb.append(columns.get(j).getText());
}else if (j==6){
sb.append(columns.get(j).getText());
}
}
System.out.println(i+""+sb.toString());
}
allpages.get(k).click();
}
但是我遇到了这个异常陈旧元素引用:元素未附加到页面文档和java.lang.IndexOutOfBoundsException:索引:2,大小:2 但是我遇到了这个异常的过时元素引用:元素未附加到页面文档中,并且java.lang.IndexOutOfBoundsException:索引:2,大小:2