How do I get a value from href?
like this eg:
Test
-
You have pointed your element to 'div' instead of 'a'
Try the below code
driverCE.findElement(By.xpath("//div[@id='testId']/a")).getAttribute("href");
讨论(0)
-
If you got more than one anchor tag, the following code snippet will help to find all the links pointed by href
//find all anchor tags in the page
List<WebElement> refList = driver.findElements(By.tagName("a"));
//iterate over web elements and use the getAttribute method to
//find the hypertext reference's value.
for(WebElement we : refList) {
System.out.println(we.getAttribute("href"));
}
讨论(0)