Saturday, 23 May 2015

How to check if Element exists on the page in Selenium Webdriver

Automation testing with Selenium often lands in the situation where you need to check if specific element exists.

We can do it very easily using below lines of code in Java.

if (driver.findElements(By.id("abc")).size() != 0)
    System.out.println("Element is present");
else    System.out.println("Element is not present");

In other language APIs like Java or Python, you can use similar method to check if element exists or not.

Please note that if you use FindElement method, NoSuchElementException will be thrown

What do you think on above selenium topic. Please provide your inputs and comments. You can write to me at reply2sagar@gmail.com

No comments:

Post a Comment

Buy Best Selenium Books

Contributors