Find an element inside a shadow DOM (Java)
QuizMedium-HardJava 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 code reads it in Selenium 4 Java with Chrome?
driver.findElement(By.id("host")).getShadowRoot().findElement(By.cssSelector("#inner"))driver.findElement(By.id("inner"))driver.findElement(By.id("host")).getShadowRoot().findElement(By.xpath(".//input"))driver.switchTo().frame("host").findElement(By.id("inner"))
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.