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 |
---|---|
|
This method checks if an element is enabled. Returns |
|
This method checks if element is selected (radio button, checkbox, and so on). ... |
Get Selenium Testing Tools Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.