Checking an element's attribute values

Developers configure various attributes of elements displayed on the web page during design or at runtime to control the behavior or style of elements when they are displayed in the browser. For example, the <input> element can be set to read-only by setting the readonly attribute.

There will be tests that need to verify that element attributes are set correctly. We can retrieve and verify an element's attribute by using the getAttribute() method of the WebElement class.

In this recipe, will check the attribute value of an element by using the getAttribute() method.

How to do it...

Create a test which locates an element and check its attribute value as follows:

@Test public void testElementAttribute() { WebElement ...

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.