bbaia / protractor-net

The .NET port of Protractor, an E2E test framework for Angular apps
MIT License
115 stars 72 forks source link

Can't interact with iframe elements inside shadow DOM #93

Closed OrestKavnyi closed 3 years ago

OrestKavnyi commented 3 years ago

We have an angular app. One of the pages has shadowRoot(open) containing an iframe. When I'm trying to write protractor test(C#) for elements inside that iframe I'm getting an error: Failed: unknown error: no element reference returned by script

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) as well as js click (using ExecuteScript) work! 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 anyone please share with me your thoughts? Thanks in advance!

bbaia commented 3 years ago

Instead of calling Click() on the NgWebElement, use the WrappedElement property to get access of the wrapped element instance and call Click().

Note that you can also use the GoToUrl(url, ensureAngularApp) method instead of IgnoreSyncronization :

ngDriver.Navigate().GoToUrl(url, false);
OrestKavnyi commented 3 years ago

@bbaia Thanks a lot for your response! Here is another thing. The moment I switch to iframe I cannot use NgWebDriver to interact with iframe elements anymore. Otherwise, I receive an exception saying "WebDriverException: javascript error: window.angular is undefined. This could be either because this is a non-Angular page or... ". Therefore, before locating any element inside that iframe, I use this line of code:

driver.IgnoreSynchronization = true;

Now, I can easily access any element. But then following your advice results in the same error anyway:

ngWebElement.WrappedElement.Click(); = unknown error: no element reference returned by script.

// where ngWebElement is any element located inside the iframe

Any ideas now? Looking forward to your response! Thank you in advance!

bbaia commented 3 years ago

I think the issue is not related to Protractor, you'll have the same error using basic WebDriver. To be confirmed!

OrestKavnyi commented 3 years ago

Yeah, it is likely to be related to Selenium WebDriver itself rather than Protractor. I was just able to reproduce the issue with a pure Selenium WebDriver and Support packages only.