Friday, August 3, 2012

Retrieving all Hyperlinks on Page with Selenium

You can retrieve the all the hyperlinks on page by this way


// Initialized  the counter and get the hyperlinks (started with //a) count

int count = selenium.getXpathCount("//a").intValue();
// run the loop till  total hyper link counter
for(int i=1;i<=count;i++)
{
//Iterate the received links through getText
String links = selenium.getText("xpath=(//a)["+i+"]" );
System.out.println("link : "+links);
}

No comments:

Post a Comment