I'm using Selenium - Java with testNG for automating webpage.
As you can see in the image of the website, there is a 'Timezone' dropdown menu with 'Please Select' as the default value. I want to locate the 'Please Select' text which is present in the <div> aria-hidden = "true" Please Select</div> line under #shadow-root (user-agent).
If I try to locate the text - 'Please Select' , I was unsuccessful.
- Getting
org.openqa.selenium.NoSuchShadowRootException: no such shadow rootexception when I tried the below method.
WebElement element = driver.findElement(By.id("timezone"));
WebElement shadowRoot1 = (WebElement) ((JavascriptExecutor)driver).executeScript("return arguments[0].shadowRoot", element);
String text = shadowRoot1.findElement(By.cssSelector("div")).getText();
System.out.println(text);
2. Also tried to locate the element using getShadowRoot() method but the same exception occurs again.
Also attaching the debugging screenshot for reference.
I don't see any
#shadow-rootin the html source code.Extracting desired text using
element.getText()is working just fine.Code example:
Output: