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]")
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.
hrefis not a DOM element ; it is a property of theaelement. See the documetation for practical examples.