-
Book Overview & Buying
-
Table Of Contents
Selenium Testing Tools Cookbook
By :
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.
Create a test which locates an element and check its attribute value as follows:
@Test
public void testElementAttribute()
{
WebElement message = driver.findElement(By.id("message"));
assertEquals("justify",message.getAttribute("align"));
}By passing the name of the attribute to the getAttribute() method, it returns the value of the attribute back to the...
Change the font size
Change margin width
Change background colour