如何从硒中的href链接获取属性值

问题描述:

我正在尝试从"a href"属性获取链接

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

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

我在做什么:

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

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

我正在获取具有"dl_link 1"类的元素,但我无法获取它的链接,字符串为空?

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

您需要使用实际属性名称调用GetAttribute().替换:

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

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

具有:

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