How to resolve, Stale element exception? if element is no longer attached to the DOM?

后端 未结 7 1196
盖世英雄少女心
盖世英雄少女心 2020-11-30 23:01

I have a question regarding \"Element is no longer attached to the DOM\".

I tried different solutions but they are working intermittent. Please suggest a solution th

7条回答
  •  星月不相逢
    2020-11-30 23:15

    I solve this by 1. keeping the stale element and poll it until it throws an exception, and then 2. wait until the element is visible again.

        boolean isStillOnOldPage = true;
        while (isStillOnOldPage) {
            try {
                theElement.getAttribute("whatever");
            } catch (StaleElementReferenceException e) {
                isStillOnOldPage = false;
            }
        }
        WebDriverWait wait = new WebDriverWait(driver, 15);
        wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("theElementId")));
    

提交回复
热议问题