Java Selenium how to get linkText (anchor) from WebElement link
I have a WebElement containing a link found by url. I can extract the url:
element.getAttribute("href");
But the question is this: how to extract its anchor, I try like this:
webElement.getAttribute("linkText");
It gives me a null value. I'm 100% sure this link has an anchor. Is there a way to get the anchor? It's more complicated, but a simplified code example might look like this:
WebDriver driver = new FirefoxDriver();
driver.get("http://stackoverflow.com/questions/tagged/java");
WebElement link = driver.findElement(By.linkText("Bicycles"));
System.out.println(link.getAttribute("href")); // shows http://bicycles.stackexchange.com/
System.out.println(link.getAttribute("linkText")); // shows null
+3
source to share