get href value (WebDriver)

后端 未结 2 933
囚心锁ツ
囚心锁ツ 2021-02-05 10:16

How do I get a value from href?

like this eg:

Test
2条回答
  •  孤街浪徒
    2021-02-05 11:05

    If you got more than one anchor tag, the following code snippet will help to find all the links pointed by href

    //find all anchor tags in the page
    List refList = driver.findElements(By.tagName("a"));
    
       //iterate over web elements and use the getAttribute method to 
       //find the hypertext reference's value.
    
        for(WebElement we : refList) {
            System.out.println(we.getAttribute("href"));
        }
    

提交回复
热议问题