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>
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?
What method can be used to retrieve the href attribute of an element? Answer: Use the jQuery . attr() Method attr() method to dynamically set or change the value of href attribute of a link or anchor tag. This method can also be used to get the value of any attribute.
Using Link Text In Selenium To Locate An Element In order to access link using link text in Selenium, the below-referenced code is used: driver. findElement(By. linkText("this is a link text"));
Definition and UsageThe href attribute specifies the URL of the page the link goes to. If the href attribute is not present, the <a> tag will not be a hyperlink.
You need to call GetAttribute()
with actual attribute name. Replace:
lists1[0].GetAttribute("a href");
with:
lists1[0].GetAttribute("href");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With