我想使用Selenium Web驱动程序在当前页面上显示超链接的URL。任何人都可以帮忙。
要获取页面上所有链接的URL,您可以将所有元素存储在WebElement列表中,然后您可以获取HREF属性以获取链接每个Webelement。
您可以参考以下代码:
List<WebElement> links = driver.findElements(By.tagName("a")); //This will store all the link WebElements into a list
for(WebElement ele: links) // This way you can take the Url of each link
{
String url = ele.getAttribute("href"); //To get the link you can use getAttribute() method with "href" as an argument
System.out.println(url);
}
只需使用getAttribute()
从HREF属性获取它们(假设您在Java中):
WebElement link = driver.findElement(By.tagName("a"))
String url = link.getAttribute("href")