在 Selenium 中獲取 Web 元素的屬性

要獲得 WebElement 的屬性,我們在 WebElement 上使用 getAttribute。例如,請考慮以下 html 標記

<a id="click" href="https://www.google.com">

我們可以通過找到 Element 的 href 屬性

WebElement e = driver.findElement(By.id("click"));
System.out.println(e.getAttribute("href")); //prints https://www.google.com