In our Selenium automated tests, we've implicit and explicit waits. As per Jim Evan's thought https://stackoverflow.com/a/15174978/1471417, they should not be mixed. Hence planning to remove implicit wait.
For our tests, whenever we interact with an element, we've used explicit wait for it to be visible, clickable etc. with ignoring NoSuchElementException
. That's why I don't think, it will throw NoSuchElementException
immediately.
This makes sure removing implicit wait won't affect my tests. Apart from this, I want to know if there are any chances it can break tests. Based on your experiences, I want to understand its impact, hence requesting to share your views here.
You saw it right. @JimEvans in this discussion clearly states that:
So, while interacting with an element Explicit Wait is the mandate.
Now, as per the constructors of WebDriverWait:
public WebDriverWait(WebDriver driver, long timeOutInSeconds)
: Wait will ignore instances ofNotFoundException
that are encountered (thrown) by default in the 'until' condition, and immediately propagate all others. You can add more to the ignore list by calling ignoring(exceptions to add).WebDriverWait(WebDriver driver, long timeOutInSeconds, long sleepInMillis)
: Wait will ignore instances ofNotFoundException
that are encountered (thrown) by default in the 'until' condition, and immediately propagate all others. You can add more to the ignore list by calling ignoring(exceptions to add).So,
WebDriverWait()
by default ignores NotFoundException and the direct known subclasses are:NoAlertPresentException
NoSuchContextException
NoSuchCookieException
NoSuchElementException
NoSuchFrameException
NoSuchWindowException
From the source code of WebDriverWait.java:
So, while using WebDriverWait you won't face NoSuchElementException. Incase the desired element is not returned till the WebDriverWait expires you will face timeoutException.