Selenium Check if Element Exists

In this tutorial you will How can check if element exists using Selenium. In Web Application testing, Visibility of Web Element is very obvious. So we will learn, How can we verify the visibility of Web Element on the web page.

 

In selenium Webdriver, we have three methods to verify the visibility of Web Element on the web page.

  • isSelected()

  • isEnabled()

  • isDisplayed()

Let’s see the use of these methods.

 

Selenium Tutorial:

If you liked this video, then please subscribe to our YouTube Channel for more video tutorials.

 

Using isDisplayed() in Selenium:

This method is used to verify that target Web Element is displaying on the Web Page or not. Using isDisplayed() method we can verify that target text, button, text box etc i.e web element is displaying on the web page or not.

Test – Verify that “Create an Account” text is displaying on the Facebook signup page.

We can do this using two ways-

  1. With the help of isDisplayed() method.

  2. Extract text from the web page and compare this using Assertion.

 

Let’s see both of the ways in separate Test cases.

You can execute the above code in your local and can see the Result. They both will work.

 

Using isEnabled() in Selenium:

This method is used to verify that target Web Element is enabled or not.  This method returns true/false on the state of web element.  If Element is enabled this will return true otherwise false.

Test – Verify that “Create an Account” button on Facebook signup page is enabled by default.

Let’s see how can we do this using selenium.

You can execute the above code in your local and can see the Result. Execute the code in Your local machine and verify the result.

 

Using isSelected() in Selenium:

This method is used to verify that target Web Element is selected or not. We can use this to verify that Check-Box, Radio Button or Drop-down is selected by default or not.

Test – Verify that “Term and Condition” Checkbox is selected on Naukri.com registration page.

Let’s see how can we do this using selenium.

This will print the text if the Term & Conditions check box will come checked by default.

 

So this is all, How we can verify the Web Elements visibility on the Web page. In Coming tutorials, we will discuss some advance tricks for hidden web elements as well.

0 Comment

Leave a Reply