Validation in Selenium WebDriver

October 9, 2016

The tutorials covered till now were focused mainly on how to automate different scenarios. In this tutorial, we will cover how to validate whether the results are as expected or not.

Validation means checking whether the UI elements are rendered on the web page correctly or not.

For Example:

  • Checking whether the hidden elements are hidden or not.
  • Checking whether the form input field is editable or not.

It’s very important to put check and validation at each and every point possible to write good automation scripts.

Every application under test has lots of validations involved during “Testing process”. Selenium provides various methods to validate UI elements.

Type of UI Validations:

  • Page Title Validation
  • Page URL Validation
  • Scroll Down
  • Verifying hidden elements
  • Checkbox Validations
  • Radio button Validations
  • To verify whether a dropdown allows multiple selections or not.
  • Read-only property of WebElement.
  • Check if an Element exists or not.
  • Textbox value validation
  • Disabled/Enabled property of a Web Element
  • Page Content Validations

Let us learn each type of validation one-by-one:

Page Title Validation: To verify the title of the page, we have a method called getTitle().

Page URL Validation: To verify the URL of the page, there is a method called getCurrentUrl().

Scroll Down Operation: There are some scenarios where web elements render on a page once you scroll down. Scroll Down operation in Selenium WebDriver can be performed by invoking JavaScript. We have covered a this in a separate tutorial Scroll Down Operation.

Hidden Element Verification: To verify whether a Web Element is visible or hidden on the page. Selenium has a method called isDisplayed(). It’s a boolean method which returns true if the WebElement is visible and return false if the method is hidden.

Checkbox Validation:  To verify that a checkbox is checked or not. Selenium provides a method called isEnabled(). It’s a boolean method which returns true if the checkbox is checked and returns false if it is not checked.

Radio Button Validation: To verify that a radio button is selected or not. Selenium provides a method called isSelected(). It’s a boolean method which returns true if it is enabled otherwise it returns false.

To verify whether a dropdown allows multiple selections or not. There is a method called isMultiple(). This method is a boolean method which returns true if the dropdown allows multiple selections else will return false.

isSelected, isMultiple and isDisplayed are three methods which can also be used to verify page contents, to verify whether a WebElement is enabled or greyed out, etc.

I hope you enjoyed the article, feel free to write us at saurabh@qatechhub.com or support@qatechhub.com. Happy Learning 🙂

Saurabh

About the Author

Saurabh

Follow Saurabh:

Leave a Comment: