how to get an attribute value from a href link in selenium

后端 未结 3 1321
余生分开走
余生分开走 2021-01-11 19:21

i am trying to get the link from \"a href\" attribute



        
相关标签:
3条回答
  • 2021-01-11 19:38

    You need to call GetAttribute() with actual attribute name. Replace:

    lists1[0].GetAttribute("a href");
    

    with:

    lists1[0].GetAttribute("href");
    
    0 讨论(0)
  • 2021-01-11 19:42

    In C#, for anchor tags

    string url = lists1[0].Url();
    

    will yield the same result as

    string url = ists1[0].GetAttribute("href");
    

    NOTE: Both returns complete Url even if the href has relative path in anchor tag.

    For <a href="/profile/my-profile-id" /> 
    
    element.Url();
    // returns http://mywebsite.com/profile/my-profile-id
    
    element.GetAttribute("href"); 
    // returns http://mywebsite.com/profile/my-profile-id
    
    0 讨论(0)
  • 2021-01-11 19:51

    C#

    element.GetAttribute("attribute name");
    

    Ruby

    element.attribute("attribute name")
    

    Python

    element.get_attribute("attribute name")
    

    Java

    element.getAttribute("attribute name")
    
    0 讨论(0)
提交回复
热议问题