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
  • 40,130
  • 10
  • 33
  • 74
Tek Nath
  • 1,374
  • 1
  • 18
  • 34

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
  • 151,581
  • 34
  • 225
  • 281
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,665
  • 2
  • 8
  • 22