[英]How to get a link href using selenium?
You can use the getAttribute
method: 您可以使用
getAttribute
方法:
String hrefText = yourLinkElement.getAttribute("href");
If you also need to find your linkElement first, you need to provide more code. 如果还需要先找到linkElement,则需要提供更多代码。
Given you only have one link Element: 假设您只有一个链接元素:
WebElement yourLinkElement = driver.findElement(By.tagName("a));
Or for example if you already identified the div-Element, that we see with the closing tag in your question you can do this: 或者例如,如果您已经标识了div-Element,我们可以在问题中使用结束标记看到该div-Element,则可以执行以下操作:
WebElement yourLinkElement = divElement.findElement(By.tagName("a));
首先找到元素,并在变量中获取其属性值,如下所述。
String linkText = webDriver.findElement(By.tagName("a")).getAttribute("href");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.