1

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>
Guy
  • 46,488
  • 10
  • 44
  • 88
Tek Nath Acharya
  • 1,676
  • 2
  • 20
  • 35

2 Answers2

1

To extract the innerHTML of an element you have to induce WebDriverWait for the visibility_of_element_located() and you can use either of the following Locator Strategy:

print(WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.CSS_SELECTOR, "element_css"))).get_attribute("innerHTML"))
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
0

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")
Muzzamil
  • 2,823
  • 2
  • 11
  • 23