Search code examples
pythonseleniuminnerhtmlgetattribute

Distorted HTML content using selenium get_attribute


I am trying to get the innerHTML of an element using:

de_nc = driver.find_element_by_css_selector('element').get_attribute("innerHTML")

But i get the following:

<a href=""https://****/""><u>Text</u></a>

Instead of the following:

<a href="https://****/"><u><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">Text</font></font></u></a>

Solution

  • You can use outerHTML attribute so it will return the HTML of the element itself with all the children elements. try this:

    de_nc = driver.find_element_by_css_selector('element').get_attribute("outerHTML")