0

I am using the WebDriverWait.Until() method in my script to wait for an element to disappear from the UI.

For this, there is the ExpectedConditions class and I could have used its InvisibilityOfElementLocated method, but it is now deprecated.

In my implementation of the WebDriverWait.Until() method, I am passing a Func delegate which has the wait logic defined inside it.

What I observe is that the exceptions, like NoSuchElementException is ignored(which I assume is due to the default whitelisted exceptions).

But I have not used the IgnoreExceptionTypes method to explicitly whitelist any exception.

I want the flow to break out of the Until method's check(which kind of keeps looping until one of the below mentioned event occurs) once an exception like NoSuchElementException is encountered.

enter image description here

Kindly suggest.

0

1 Answer 1

0

If you are providing automation testing services then you need to play with the waits for application to application. Put the code in try catch block and wait for the element only if it present:

if (isElementDisplayed(By.xpath("abc"))) {
            waitForInvisibilityOfElement(webelement, 90);
        }


 public boolean isElementDisplayed(By by) {
        WebElement webElement = null;

        boolean displayed;
        try {
            webElement = this.getWebDriverFacade().getWebDriver().findElement(by);
            displayed = webElement.isDisplayed();
        } catch (StaleElementReferenceException var7) {
            try {
                webElement = this.getWebDriverFacade().getWebDriver().findElement(by);
                webElement.isDisplayed();
                displayed = true;
                logElementState(webElement, displayed, "exist");
            } catch (WebDriverException var6) {
                displayed = false;
                LOGGER.trace("[ELEMENT] {} is NOT {}", displayed, "exist");
            }
        } catch (WebDriverException var8) {
            displayed = false;
        }

        logElementState(webElement, displayed, "displayed");
        return displayed;
    }





 public void waitForInvisibilityOfElement(WebElement element, long timeoutInSeconds) {
        LOGGER.trace("[WAIT FOR] invisibility of element");

        try {
            this.getStandardWait().ignoring(NoSuchElementException.class).withTimeout(Duration.ofSeconds(timeoutInSeconds)).until(ExpectedConditions.invisibilityOf(element));
        } catch (NoSuchElementException var5) {
        }

    }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.