WebdriverWait is not Ignoring NoSuchElement Exception

582 views
Skip to first unread message

Matthew Vass

unread,
Mar 25, 2016, 11:06:51 AM3/25/16
to Selenium Users
I've been racking my brain over why this isn't working.  No matter what I do this will not work, so I'm hoping someone in the community can help me solve this issue.

The problem comes with a custom function I've written for waiting if an element is visible or not.  I have several other function that do other explicit waits that all seem to have the same issue.  I recently updated my code to turn off implicit waits while executing explicit waits to get a correct wait time.  This is when I noticed my code was not working at all. Below is my code snippet, I have an ajax modal that when it's triggered i need to wait for specific items to be there and that modal gets re-used which is why i need explicit instead of implicit waits for certain scenarios. The code below throws a NoSuchElement exception instead of ignoring and waiting for it.  Any ideas??

     public boolean elementVisible(By by, long seconds) {
WebDriverWait wait = new WebDriverWait(this.driver, seconds);
return wait
.ignoring(StaleElementReferenceException.class)
.ignoring(NoSuchElementException.class)
.pollingEvery(300, TimeUnit.MILLISECONDS)
.until(ExpectedConditions
.visibilityOfElementLocated(by)) != null;
}

Matthew Vass

unread,
Mar 25, 2016, 3:58:26 PM3/25/16
to Selenium Users
So I found that prior to calling this in my code something else was accessing the elements findBy causing the no such element prior to the wait actually happening.
Reply all
Reply to author
Forward
0 new messages