O'Reilly logo

Selenium Testing Tools Cookbook by Unmesh Gundecha

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Checking an element's status

Many a time a test fails to click on an element or enter text in a field as the element is disabled or exists in the DOM, but is not displayed on the page; this will result in an error being thrown and the test resulting in failures. For building reliable tests that can run unattended, a robust exception and error handling is needed in the test flow.

We can handle these problems by checking the state of elements. The WebElement class provides the following methods to check the state of an element:

Method

Purpose

isEnabled()

This method checks if an element is enabled. Returns true if enabled, else false for disabled.

isSelected()

This method checks if element is selected (radio button, checkbox, and so on). ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required