我正在爲鼠標懸停工作,我想通過單擊每個使用for循環的鏈接來測試所有鏈接的工作條件。在我的程序中,迭代進行一次,對於下一次迭代它不是工作,展示了「StaleElementReferenceException」 .......... 如果需要的話請不要在代碼修改....如何處理StaleElementReferenceException
public static void main(String[] args) throws IOException
{
WebDriver driver = new FirefoxDriver();
Autoit.Authenti(driver);
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(20,TimeUnit.SECONDS);
driver.get("http://staging.zenrays.com");
Actions a1=new Actions(driver);
WebElement cl=driver.findElement(By.xpath(".//*[@id='menu-450-2']/a"));
a1.moveToElement(cl).perform();
WebDriverWait wait =new WebDriverWait(driver, 30);
List<WebElement> links=driver.findElements(By.xpath("//a[contains(@class,'sf-depth-2')]"));
for(int i=0;i<=links.size()-1;i++)
{
links.get(i).click();
driver.navigate().back();
}
}
}
您能提供一些關於您想要執行的確切步驟的更多信息嗎? – DebanjanB
請訪問鏈接(「zenrays.com」),在那裏您可以看到課程鏈接(頁面標題),其鼠標懸停鏈接,並有13個子鏈接,我想通過單擊和測試每個子鏈接導航回到主頁,以便我用於循環。它正在爲第一個子鏈接和導航返回主頁也爲第二次迭代它顯示異常.......... – swamynathan