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

时间:2022-11-27 18:32:09

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

我试图从“a href”属性获取链接

<a href="http://fgkzc.downloader.info/download.php?id=bc56585624bbaf29ebdd65d0248cb620" 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?

我正在获取类“dl_link 1”的元素,但我无法得到它的链接,字符串为空?

2 个解决方案

#1


10  

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

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

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

with:

有:

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

#2


2  

C#

C#

element.GetAttribute("attribute name");

Ruby

红宝石

element.attribute("attribute name")

Python

蟒蛇

element.get_attribute("attribute name")

Java

Java的

element.getAttribute("attribute name")

#1


10  

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

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

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

with:

有:

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

#2


2  

C#

C#

element.GetAttribute("attribute name");

Ruby

红宝石

element.attribute("attribute name")

Python

蟒蛇

element.get_attribute("attribute name")

Java

Java的

element.getAttribute("attribute name")