user3181034 user3181034 - 1 year ago 172
C# Question

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

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

<a href="" rel="nofollow" class="dl_link 1" style="">Download</a>

what i am doing:

ReadOnlyCollection<IWebElement> lists1 = driver.FindElements(By.ClassName("dl_link"));

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

i am getting the element with class "dl_link 1" but i can't get it's link, the string is null?

Answer Source

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

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


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download