I have the following HTML code:
2
<
If your HTML consists solely of that one <a>
tag, then this should do it:
String href = selenium.getAttribute("css=a@href");
You use the DefaultSelenium#getAttribute() method and pass in a CSS locator, an @
symbol, and the name of the attribute you want to fetch. In this case, you select the a
and get its @href
.
In response to your comment/edit:
The part after @
tells Selenium that that part is the name of the attribute.
You should place :contains('2')
before @href
because it's part of the locator, not the attribute. So, like this:
selenium.getAttribute("css=a:contains('2')@href");
Changing css=a@href to href should do the trick. Let me if this did not work.
List<WebElement> ele = driver.findElements(By.className("c"));
for(WebElement e : ele)
{
String doctorname = e.getText();
String linkValue = e.getAttribute("href");
}