I have written few test cases in Selenium WebDriver using Java and execute them on grid (hub and multiple nodes). I have noticed that a few test cases fail due to NoSu
NoSuchElementException occurs, when the locators (i.e. id / xpath/ css selectors) is unable to find the web element on the web page.
The reasons for this could be :
Incorrect Locator
Web element not available on web page
In order to avoid this exception, we can use Fluent Wait. This wait allows us to define max timeout, polling frequency and define which exception to ignore.
Please find the sample usage of Fluent wait below :
.withTimeout(50, TimeUnit.SECONDS)
.pollingevery(3, TimeUnit.SECONDS)
.ignoring(NoSuchElementException.class);