如何从硒中的href链接获取属性值 [英] how to get an attribute value from a href link in selenium
本文介绍了如何从硒中的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");
这篇关于如何从硒中的href链接获取属性值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文