Shadow Dom: Its a functionality , that allows the web browser to render some DOM elements without putting them into the main document DOM tree
Steps:
1.find host above id inside its placed
2.find root using .getShadowRoot (); method like SC root=hostelement.getShadowRoot ();
3.find actaul using root.findelemnet()
public class Sample
{
public class Sample{
public SearchContext expandRootElement (WebElement element) {
SearchContext shadowRoot = (SearchContext) ((JavascriptExecutor) getDriver ()).executeScript (
"return arguments[0].shadowRoot", element);
return shadowRoot;
}
public Webelemnt getSomeText () {
return getDriver ().findElement (By.cssSelector ("#shadow_content > span"))
;
}
public Webelemnt getShadowDomText () {
WebElement shadowHost = getDriver ().findElement (By.id ("shadow_host"));
SearchContext shadowRoot = shadowHost.getShadowRoot ();
return = shadowRoot.findElement (By.cssSelector ("#shadow_content > span"))
;
}
public Webelemnt fetchNestedShadowText () {
WebElement shadowHost = getDriver ().findElement (By.id ("shadow_host"));
SearchContext shadowRoot = shadowHost.getShadowRoot ();
WebElement shadowContent = shadowRoot.findElement (By.cssSelector ("#nested_shadow_host"));
SearchContext shadowRootTwo = shadowContent.getShadowRoot ();
return shadowRootTwo.findElement (By.cssSelector ("#nested_shadow_content > div"));
return
}
public Webelemnt FetchNestedText() {
WebElement nested = getDriver ().findElement (By.id ("shadow_host")).getShadowRoot ()
.findElement (By.cssSelector ("#nested_shadow_host")).getShadowRoot ()
.findElement (By.cssSelector ("#nested_shadow_content > div"));
return nested;
}
public Webelemnt fetchNestedTextUsingJSExecutor () {
WebElement shadowHost = getDriver ().findElement (By.id ("shadow_host"));
SearchContext shadowRootOne = expandRootElement (shadowHost);
WebElement nestedShadowHost = shadowRootOne.findElement (By.cssSelector ("#nested_shadow_host"));
SearchContext shadowRootTwo = expandRootElement (nestedShadowHost);
return shadowRootTwo.findElement (By.cssSelector ("#nested_shadow_content > div"))
}
}
}
IJavaScriptExecutor jse2 = (IJavaScriptExecutor)_driver;
var pdfUrl = jse2.ExecuteScript("return document.querySelector('downloads-manager').shadowRoot.querySelector('downloads-item').shadowRoot.getElementById('file-icon').getAttribute('src')");