I am trying to print nested shadow element text using below code but no luck. I have tried to use same code throough console windows and its giving me expected text.
Code :
import org.openqa.selenium.JavascriptException;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
public class ShadowRoot {
public static void main(String[] args) throws InterruptedException {
WebDriver driver;
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.addArguments("--remote-allow-origins=*", "ignore-certificate-errors");
driver = new ChromeDriver(chromeOptions);
// browser type and chromedrover.exe path as parameters
System.setProperty("webdriver.chrome.driver", "chromedriver.exe");
String url = "http://watir.com/examples/shadow_dom.html";
driver.get(url);
JavascriptExecutor js = (JavascriptExecutor) driver;
// js.executeScript("document.querySelector('#shadow_host').shadowRoot.querySelector('input').value='username'");
js.executeScript("document.querySelector('#shadow_host').shadowRoot.querySelector('#nested_shadow_host').shadowRoot.querySelector('#nested_shadow_content > div').innerText");
Thread.sleep(10000);
driver.close();
}
}