protractor
protractor copied to clipboard
Can't access iframe elements inside shadow dom
I have an angular app with enabled ViewEncapsulation.ShadowDom, inside which there is an iframe. When I'm trying to write protractor test I'm getting an error:
Failed: unknown error: no element reference returned by script
While I'm able to actually get web element, I can't perform any actions with it.
const root = element(by.css('app-root')).getWebElement();
browser.driver
.executeScript('return arguments[0].shadowRoot', root)
.then((shadowRoot: WebElement) => {
browser.switchTo()
.frame(shadowRoot.findElement(by.css('iframe')))
.then(()=>{
element(by.css('.app-block')).getWebElement().then(el=>{
console.log("EL:",el); //logs element
browser.actions().mouseMove(el).perform(); //throws error
});
});
});
If this currently achievable or I should turn off shadow dom for test build?
We also faced with the same issue during attempt access to element in shadow dom. Unfortunately, this doesn’t work in Protractor.
@lexigren @StanislavKharchenko Hi, I am facing the same issue right now (C# + Protractor). We also have an Angular-based application but I am not sure Angular is used on that particular iframe, - when trying to locate any element, I receive an exception saying "...Angular is not defined on this page...". Once I set IgnoreSyncronization property to true or/and fetch the WrappedDriver I stop receiving that exception and elements get located. But then if I want to click that element I get: unknown error: no element reference returned by script. Interesting that imitating a click with SendKeys(Keys.Enter) works as well as js click (using ExecuteScript)! So, I assume there is some interaction and I switched to that iframe correctly. But what is the matter with a Click(), - I don't get. Could you guys please share with me your thoughts? It's been a while since that question was published, maybe you already solved that issue or have more info about it. Thanks in advance!