Reputation: 33
How to locate the href elements using selenium and python
i tried below code but its not working
driver.find_element_by_xpath("//a[@href]")
Upvotes: 0
Views: 1196
Reputation: 967
Try below code with replacing href attribute value with your value.
driver.find_element_by_xpath("//a[@href='href attribute value']");
Upvotes: 0
Reputation: 52685
To locate href
attribute usually you can use
//a/@href
but selenium
doesn't support this syntax as in selenium
you can locate webelements only.
You can try below:
driver.find_element_by_xpath("//a").get_attribute('href')
With this line of code you should be able to get href
attribute of the first anchor element on the page.
Upvotes: 2