我有下面的代码,在执行时,它会纠正我期望的页面并点击所需的链接。但是,结果总是显示Fail而不是Pass。在for循环的最后一步之后,焦点跳转到catch循环并打印resultDetails.setFlag(false)
并且case失败。请让我知道我错在哪里。
driver.findElement(By.linkText("ALL EQUIPMENT")).click();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
List <WebElement> listings = driver.findElements(By.cssSelector("a[href*='/listing?listingid']"));
try {
for (int i=0; i < listings.size(); i++) {
WebElement requiredlisting = listings.get(i);
requiredlisting.click();
getvalue = driver.findElement(By.xpath("//div[7]/span")).getText();
System.out.println(getvalue);
driver.findElement(By.xpath("//div[3]/div[2]/input")).click();
Thread.sleep(10000);
driver.findElement(By.id("listingQuestion")).click();
Thread.sleep(10000);
driver.findElement(By.id("listingQuestion")).sendKeys("Where is the listing located");
Thread.sleep(10000);
driver.findElement(By.name("submitq")).click();
Thread.sleep(10000);
driver.findElement(By.xpath("//div/div[2]/div[3]/input")).click();
Thread.sleep(10000);
driver.findElement(By.id("uname")).click();
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
driver.findElement(By.linkText("Sign Out")).click();
driver.manage().deleteAllCookies();
driver.navigate().refresh();
driver.get(field);
driver.findElement(By.id("aurid")).sendKeys("mglaz@assetnation.com");
driver.findElement(By.id("apwd")).sendKeys("Equipment1$");
driver.findElement(By.xpath("//input[@value='Login']")).click();
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
driver.findElement(By.id("userAgreementBtn")).click();
Thread.sleep(10000);
System.out.println(getvalue);
driver.findElement(By.id("quicksearch")).sendKeys(getvalue);
Thread.sleep(10000);
driver.findElement(By.cssSelector("input.quicksearch_go")).click();
Thread.sleep(20000);
driver.findElement(By.linkText("Lot Q/A")).click();
Thread.sleep(10000);
driver.getPageSource().contains("my question");
driver.manage().deleteAllCookies();
driver.navigate().refresh();
resultDetails.setFlag(true);
}
}
catch (Exception e ) {
resultDetails.setFlag(false);
}
答案 0 :(得分:0)
你在&#39; listing&#39;中持有webelemets。通过使用for循环,您将获取一个元素并执行大量操作,以便更改页面。如果你从列表中调用另一个webelement,它通常会因为它被更改而失去它对页面的关注,你就会得到那个stale_element_exception ..
我希望你需要在这里检查/更改逻辑,如果我没有错的话......
谢谢你, 穆拉利