I am trying to search Google for Selenium, then run down the list of links by clicking each one, printing the page title, then navigating back.
List linkElements = driver.findElements( **** );
for(WebElement elem: linkElements)
{
String text = elem.getText();
driver.findElement(By.linkText(text)).click();
System.out.println("Title of link\t:\t" + driver.getTitle());
driver.navigate().back();
}
To find the elements, I have tried By.tagName("a") which doesn't work because it gets ALL the links, not just the search ones. Using Firebug, I see that each search link has a class of r used on the header h3, and the a tag nested inside it.
See the following:
Selenium - Web Browser Automation
What code can I insert to make this work?