Selenium webdriver and shadow dom elements | Selenium Forum
M
Posted on 08/02/2017
Hi

I'm trying to locate shadow dom elements. I'm using Chrome browser. Selenium with C#

This is my HTML view

I have attached the html source

I'm trying to reach the attribute - Administrator and in order to do so I first need to located the input box which has the id as input.
Now that is in the shadow root. Not sure how to get there. This is the code I have so far.


IWebElement step1loginWrapper = driver.FindElement(By.ClassName("oc-loginWrapper"));
//get shadow root element - the first shadow root
IWebElement shadowRoot1 = expandRootElement(step1loginWrapper);

IWebElement step2loginControl = driver.FindElement(By.CssSelector("oc-login-control"));
//get shadow root element - the second shadow root
IWebElement shadowRoot2 = expandRootElement(step2loginControl);

IWebElement inputelement = driver.FindElement(By.TagName("div"));
IWebElement test1 = expandRootElement(inputelement);

IWebElement inputelement1 = driver.FindElement(By.TagName("div"));
IWebElement test2 = expandRootElement(inputelement);

IWebElement paper = driver.FindElement(By.TagName("paper-material"));
//get shadow root - the third shadow root
IWebElement shadowRoot3= expandRootElement(paper);
IWebElement username = shadowRoot3.FindElement(By.Id("input"));


My javascript executor method is

public IWebElement expandRootElement(IWebElement element)
{
IWebElement ele = (IWebElement)((IJavaScriptExecutor)driver)
.ExecuteScript("return arguments[0].shadowRoot", element);
return ele;
}



It throws an exception "unable to locate element paper-material"

I have been trying to figure this out for almost two days and was unsuccessful. Appreciate your support.

Thanks,
Sharmila