Skip to content
CodeKruPro

Find an element inside a shadow DOM (Python)

QuizMedium-HardPython onlyAsked in: Happiest Minds

A shadow root is a hidden sub-document attached to an element, used by web components (reusable page parts). An input with id inner sits inside the open shadow root of <div id="host">. Which Python code reads its value in Chrome?

  • driver.find_element(By.ID, "host").shadow_root.find_element(By.CSS_SELECTOR, "#inner").get_attribute("value")
  • driver.find_element(By.ID, "inner").get_attribute("value")
  • driver.find_element(By.ID, "host").shadow_root().find_element(By.XPATH, ".//input")
  • driver.switch_to.frame("host") and then search

This question is part of Pro+

Pro+ opens every question in Interview Prep and the mock interview. Every article and the first 2 questions of each topic stay free. Hands-on Selenium and API tasks follow their course lesson's own lock.

See Pro+

Already have Pro+? Sign in