Friday, 15 August 2014

GetAttribute Method in Selenium





-> This method used to Gets the value of the specified attribute for this Web element.

Syntex:

WebElement.GetAttribute("Attribute_Name")

o/p

Returns the value of the Attribute name.



Example:



Source :

<a id="link1" href="http:gmail.com">
<span lang="LBLSHOVIDEOS">Selenium</span></a>


Script :


String attr1=driver1.findElement(By.linkText("Selenium")).getAttribute("id");
System.out.println("Attribute ID Value="+attr1);

String attr2=driver1.findElement(By.linkText("Selenium")).getAttribute("href");
System.out.println("Attribute HREF Value="+attr2);



O/P :

Attribute ID Value= Link1

Attribute HREF Value=http:gmail.com

No comments:

Post a Comment