当我执行此循环时,我收到错误,因为元素未附加到第二轮循环中的页面文档。有关详细信息,请单击“报告”菜单,该页面包含报告列表。在for循环中,我单击第一个报告并进行一些验证。使用breadcrumb我返回到报告页面,点击列表中的第二个。在尝试获取报告名称时出现错误。为此,我有一个解决方法,我在for循环结束时重新创建了列表webelement,并将新weblist重新分配给旧的webelement。我想知道的是这是一个好方法,还是我应该使用其他更有效的方法
driver.findElement(By.xpath("//block[contains(text(),'Reports')]")).click();
waitForElement(By.cssSelector(".reports-list a"));
List <WebElement> reportNames = driver.findElements(By.cssSelector(".reports-list a"));
for (int i=1; i<reportNames.size();i++) {
reportName=reportNames.get(i).getText();
System.out.println(reportName);
reportNames.get(i).click();
try {
while(!waitForNotAttribute(driver.findElement(By.cssSelector("body[class='noScroll']"))))
System.out.println("Element Gone");
} catch (Exception e) {
//e.printStackTrace();
}
boolean isclickable = isElementPresent(By.cssSelector(".table-row .clickable i"));
String varClick =".reports-row";
if (isclickable) {
driver.findElement(By.cssSelector(".table-row .clickable i[ng-show='!rowdata.expanded && rowdata.groupingRow']")).click();
varClick ="reports-row";
}
List <WebElement> clickableCount = driver.findElements(By.cssSelector("reports-row "+varClick+" .rightJustify .clickable"));
for (int a=1; a<=clickableCount.size(); a++) {
if (reportName.equals("Student Count")){
//calling a function
selectReport(a, reportName, varClick);
}else {
selectReport(2, reportName, varClick);
break;
}
driver.findElement(By.xpath("//*[@class='breadcrumb ng-scope layout-row']/span/a[contains(text(),'Reports')]")).click();
List <WebElement> reportNames1 = driver.findElements(By.cssSelector(".reports-list a"));
reportNames=reportNames1;
}