I'm trying to get the URL link from an element with get_attribute('href') mode. However it returns null, like it didn't have href.
webdriver.find_element_by_xpath('//*[@id="__next"]/main/div[3]/div/section[1]/div/a[1]').get_attribute('href');
If I click manually, or use click( ) function, it will get me to the URL of the button, so there is a hyperlink associated to that button.
The html code of the element is that below:
<a data-testid="subcategory-content-with-no-link" >Mastite</a>
How can I get the URL/hyperlink of that button using Selenium?
Edit:
There's no href in any element inside <div>
class as can be seen on this printscreen of html code.
CodePudding user response:
The html code that you posted shows that there is not href
atteibute associated with that element. See if for example a parent element (possibly div
) contains the href
attribute instead.
CodePudding user response:
Though on clicking the desired element you will be redirect to the desired URL but the href
attribute is absent can be easily acknowledged from the value of the data-testid
set as subcategory-content-with-no-link.
However, it needs to be emphasized that the href
attribute is obfuscated within the class attribute value: