Home > Mobile >  How do I get href attribute value from the given HTML using Python Selenium?
How do I get href attribute value from the given HTML using Python Selenium?

Time:04-18

I have HTML as shown (modified to make it brief)

ht=<a  href="http:/www.myref.com/1235" title="This is link to my ref">This is my ref</a>

Now from here, I want to extract the "http:/www.myref.com/1235"

ht.get_text()

gives me only the text part This is my ref.

Please help. Thanks in advance.

CodePudding user response:

If ht is a webelement then,

ht.get_attribute('href')

should give you http:/www.myref.com/1235

Since you are getting TypeError: 'NoneType' object is not callable

This could mean either

  1. ht is not a web element.

  2. ht is not rendered properly.

Put some delay before ht and try again with ht.get_attribute('href')

  • Related