To get the attribute of a WebElement
, we use getAttribute
on that WebElement
. For example, consider the following html tag
<a id="click" href="https://www.google.com">
We can find the Element's href
attribute by
WebElement e = driver.findElement(By.id("click"));
System.out.println(e.getAttribute("href")); //prints https://www.google.com