Back

Explore Courses Blog Tutorials Interview Questions
0 votes
1 view
in DevOps and Agile by (19.7k points)

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 NoSuchElementException. What is the best and robust way to avoid NoSuchElementException and ensure the element is always found?

1 Answer

0 votes
by (62.9k points)

You can never be sure that element will be found, actually, this is the purpose of functional tests - to tell you if anything changed on your page. But one thing that definitely helps is to add waits for the elements which are often causing NoSuchElementException like

WebDriverWait wait = new WebDriverWait(webDriver, timeoutInSeconds);

wait.until(ExpectedConditions.visibilityOfElementLocated(By.id<locator>));

Welcome to Intellipaat Community. Get your technical queries answered by top developers!

28.4k questions

29.7k answers

500 comments

94k users

Browse Categories

...