Wednesday, 4 April 2012

Finding the Class name from Xpath of an Element in Selenium

Sometimes, we may require to find the Class name of an element whoes xpath we know.
We can use the "getAttribute()"  method of Selenium to handle this situvation.

consider the example below:

String Name=webDriver.findElement(By.xpath(//div[@class='hotelRoomCard'][5]/span[2]/button).getAttribute("class");
System.out.println("The class name is:"+Name);

The output will geive you the class name.
This in turn can be used to identify the object with a desired class name.
Hope it was helpfull.... :)

No comments:

Post a Comment