How to get attribute value from href link in selenium

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

<a href="http://fgkzc.downloader.info/download.php?id=bc56585624bbaf29ebdd65d0248cb620" rel="nofollow" class="dl_link 1" style="">Download</a>

What am I doing:

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

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

I get an element with class "dl_link 1", but I can’t get its link, is the string null?

+4
source share
2 answers

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

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

from:

lists1[0].GetAttribute("href");
+8
source

FROM#

element.GetAttribute("attribute name");

ruby

element.attribute("attribute name")

Python

element.get_attribute("attribute name")

Java

element.getAttribute("attribute name")
+1
source

Source: https://habr.com/ru/post/1607738/


All Articles