Pages

Wednesday, 7 March 2012

How can I get required attribute value of the element?

We can get the specific attribute of an element by using getAttribute() method:


//Find the element
WebElement gButton = driver.findElement(By.name("btnK"));
// Get the required attribute value
String gButtonStyle = gButton.getAttribute("style");

System.out.println("The Google search button's style attribute value is "+gButtonStyle);

The getAttribute() method gets the value of an element attribute specified.


Suppose, you want to get the value/content of a text field then, specify the attribute name as “value” (instead off “style”).

No comments:

Post a Comment