首页 > 解决方案 > 更新了问题 - 尽管放入了 try catch,但获取过时的元素异常,等到异常元素可见

问题描述

*我stale element Exception在这部分得到了一个:

我从表中获取 id

这是导致陈旧元素的部分:


latestId.click();
        
    

我试过:使用下面的代码:

 WebDriverWait wait = new WebDriverWait(driver,10);```
  wait.until(ExpectedConditions.refreshed(ExpectedConditions.stalenessOf(latestId)));

基本上在方法中,因为 id.click() 和 createdvalue("id",latestid.gettexxt()) 都存在它导致问题。

我能得到一个解决方案吗..如果需要可以添加更多信息*

标签: javaseleniumautomationcucumberautomation-testing

解决方案


您尚未共享元素的 ID 查找代码。

我建议你这样做:

  1. 通过其已知 ID 再次查找该元素。
  2. 等待元素可点击
  3. 点击它

代码:

    WebDriverWait wait = new WebDriverWait(driver, 30);
    WebElement myElement = wait.until(ExpectedConditions.elementToBeClickable(By.id("TheID")));
    try {
        Actions builder = new Actions(browser);
        builder.moveToElement(myElement).click().build().perform();
    } catch (Exception x1) {
        myElement.click();
    }

推荐阅读