在 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