-
Notifications
You must be signed in to change notification settings - Fork 2.3k
ShadowDOM support request #4367
Comments
Tnx for sharing this. It looks nice and it's a nice workaround. If you would like to see this in a newer version of Protractor you could add a PR with a new locator like |
@wswebcreation Ok, good. I will add a PR. |
Looks good to me 👍 I'm only not the (only) one who decides about the PR's. The core members, that will also review your PR, decide in the end. I think it will be a great addition and a clear logging, so go for it 😉 |
@wswebcreation How can I push my commits? Seems that I have no enough permission to contribute. |
@wswebcreation Yes, I checked
Now what should I do for next? |
Hi @First87,
That should do the trick |
@wswebcreation Ok, thank you for guiding. |
@wswebcreation I just created a PR #4392. |
@First87 Tnx!! |
What is the status on this? We would like to be able to use the by.shadowRoot function. |
Hope someone helps me resolve this: #4392 (comment) |
@First87 I tried using your new locator in my e2e tests. I am unable to get the elements in the shadow dom. Environment: Angular (v5) Application with Polymer Web Components. Protractor for running e2e tests. Angular CLI: 1.6.4 I am unable to access input element inside custom polymer component using protractor by.css_sr. var polymerFirstName = element(by.className('polyFName')); It failed with an error "No element found using locator: by.css_sr("input")". I need to access the inner input element so that I can perform UI Automation tasks like. Anything I am missing? |
@msbasanth You missed
|
Thank you @First87 it worked like a charm. |
This works! Thank you! It's going to be so hard locating elements now especially if there are nested shadow doms :( since we can't test the locators in the console. Thanks again! |
@firstor Thank you so much for this! Hopefully this can get integrated soon.... I was hoping to get some assistance from you on this though. While I am able to get the correct value using ::sr as needed, when I do Expected [ 'Title' ] to be 'Title'. I have not had success in being able to get the string from that object/array and was wondering if you had an any idea? Thanks again for the workaround!! EDIT: Disregard!! Referenced this and it did the trick https://stackoverflow.com/questions/29478905/protractor-element-gettext-returns-an-object-and-not-string. Thanks again!! |
Hi @firstor / @msbasanth , I am unable to get an element present in shadow-root DOM. I copied your above code in a .ts file but getting a compilation error at line no. 6: Application: Angular v7 Can you please elaborate on how to use your method to enter some text in the input box inside shadow-root? |
@firstor Am getting the below error What am i doing wrong? |
Any update on this? |
any update? this is a blocker for many specs as of late( |
Hello @firstor , Application : Angular 8 Thank you for your workaround. I try to find element into ShadowRoot. In our frontend architecture, we Have 3 depth levels
First and second shadowRoot level are accessible but not the last one. Extract of the Code source :
Result logs :
We try with other solution (https://stackoverflow.com/questions/57979981/how-to-check-in-protractor-javescript-in-shadow-dom-if-the-button-is-enabled-o). We have the same issue :
Result :
Is there a limit regarding shadowRoot depth limit access ? Thanks you for your support. V1nc3kr0 |
Give a try like |
@firstor |
Hello guys , could any one tell me where to include that script ? @firstor , @alagappan-qa thanks in advance. |
Hi, Is it possible to include this script in a separate js file and import it in the protractor.conf file and include in onPrepare() method. If so, how do we do it ? Thanks, |
If anyone needs this now, see #4786 (comment) and #4786 (comment) You can also use https://github.com/angular/protractor/pull/4786.patch or https://github.com/angular/protractor/pull/4786.diff |
@Lakhs02
Then in the onPrepare() method
|
@firstor I can see on your profile that you are experienced with shadow DOM. Could you please be so kind and provide an example how you access nested shadow DOM? I am struggling with it for two weeks now and still cannot access some elements: I tried the below locator (and many others) but with no success: What is suprising, the locator for app-project works fine, but when I go deeper, whatever I try, it does not work. Do you have any idea what am I doing wrong? |
Hi Magda, |
OMG, I got it now, and I am able to find all locators I need!
Thank you so much for help !
Best regards,
Magda
From: alagappan-qa <notifications@github.com>
Sent: Saturday, July 4, 2020 4:34 AM
To: angular/protractor <protractor@noreply.github.com>
Cc: Bartkowiak-Jowsa, Magdalena <magdalena.bartkowiak-jowsa@capgemini.com>; Comment <comment@noreply.github.com>
Subject: Re: [angular/protractor] ShadowDOM support request (#4367)
@firstor<https://github.com/firstor>
My Web Application is using Polymer.js with 10 levels of Shadow roots.
[Image removed by sender. RJvlf]<https://user-images.githubusercontent.com/57852329/72205775-de7d6300-34ac-11ea-93f7-37917052ce90.png>
Is it possible to call the last Shadow root element from the top node instead of traversing the individual Shadow roots.
Thanks for your support.
@firstor<https://github.com/firstor> I can see on your profile that you are experienced with shadow DOM. Could you please be so kind and provide an example how you access nested shadow DOM? I am struggling with it for two weeks now and still cannot access some elements:
This is my example, I need to access highlighted div element: div.a-choosen-text:
[Image removed by sender. image]<https://user-images.githubusercontent.com/50359393/86498151-c532e080-bd84-11ea-867c-337085b96087.png>
I tried the below locator (and many others) but with no success:
nameOnTheProjectTab = element(by.css_sr('app-dumbledore::sr lit-route::sr app-dashboard::sr app-project:nth-child(1)::sr appkit-panel::sr app-assignee-dropdown::sr appkit-dropdown::sr div.a-choosen-text'));
What is suprising, the locator for app-project works fine, but when I go deeper, whatever I try, it does not work.
Works fine: static projectTab = element(by.css_sr('app-dumbledore::sr lit-route::sr app-dashboard::sr app-project:nth-child(1)'));
Do you have any idea what am I doing wrong?
Thank you in advance,
Magda
Hi Magda,
In your case, the shadow root under the WebElement appkit-panel is not expanded to find out your Element.
But in the nameOnTheProjectTab element it's expanded which causes this issue.
Try out the below element locator,
nameOnTheProjectTab = element(by.css_sr('app-dumbledore::sr lit-route::sr app-dashboard::sr app-project:nth-child(1)::sr app-assignee-dropdown::sr appkit-dropdown::sr div.a-choosen-text'));
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub<#4367 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AMAGYYOPZMDJCRSHT5XI45TRZ2ILDANCNFSM4DR44ABQ>.
…________________________________
Capgemini Polska Sp. z o.o.,
ul. Żwirki i Wigury 16a 02-092 Warszawa,
S?d Rejonowy dla M.ST. Warszawy, XII Wydzia? Gospodarczy Rejestrowy, nr KRS: 0000040605,
NIP: 526-11-84-467,
Wysoko?? kapita?u zak?adowego: 16.403.320,00 z?.
This message contains information that may be privileged or confidential and is the property of the Capgemini Group. It is intended only for the person to whom it is addressed. If you are not the intended recipient, you are not authorized to read, print, retain, copy, disseminate, distribute, or use this message or any part thereof. If you receive this message in error, please notify the sender immediately and delete all copies of this message.
|
Hey Everyone, Found a solution to locate the Shadow Elements inside the Shadow Root at any deep level. |
Hi Alagappan,
can you please describe a little more with an example please.Thanks
…On Wed, Aug 19, 2020 at 7:52 AM alagappan-annamalai < ***@***.***> wrote:
Hey Everyone, Found a solution to locate the Shadow Elements inside the
Shadow Root at any deep level.
With the help of the node module "query-selector-shadow-dom", we can
identify the Web elements in the Shadow DOM with ease. No need to traverse
through all the Shadow roots.
Using element(by.shadowDomCss('')), we can point to the Web element inside
the Shadow Root at any level.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#4367 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AK2OQDTZK2ZVJTICP3VGS3DSBPDJVANCNFSM4DR44ABQ>
.
|
|
I also got this error and the solution is to replace By the way @firstor, thank you for this contribution! It has been working great so far. I wasted so much time trying to get |
@rob4226 Looks promising. |
@msbasanth @rob4226 I'm new to protractor, I'm trying to access text 'Downloads' of chrome download page Appreciate your response on this Thanks! |
I fixed it, I need to create separate element variable for every nested shadow root element. @firstor I greatly appreciate for this code. many thanks 👍 |
Hello i am currently tr to select shadow dom. I get the following error when using the workaround:
Usage:
|
Hi @wasoek , Can you provide the Chrome Developer Tool > Inspect Element for this element from the Shadow Root. That will give more details on this issue. |
Hi,
This can be handled using any of the below 2 methods,
Let element1 = element.all(by.css_shadowroot('downloads-manager::sr div’)).get(1)
Let element2 = element1.element(by.css_shadowroot(‘::sr downloads-item::sr div::sr downloads-item')).getText();
OR
browser.element(by.css_shadowroot('downloads-manager::sr div[id=”mainContainer”]::sr downloads-item::sr div::sr downloads-item')).getText();
[here instead of nth child we are using the ID, so that it’ll focus to the element]
Thanks,
Alagappan A
From: shopmujahid <notifications@github.com>
Sent: Thursday, December 3, 2020 9:20 AM
To: angular/protractor <protractor@noreply.github.com>
Cc: Alagappan Annamalai <alagappan.annamalai@riversand.com>; Comment <comment@noreply.github.com>
Subject: Re: [angular/protractor] ShadowDOM support request (#4367)
I'm trying to access elements under second div element of shadow dom (highlighted) but it is always retrieving the first div element with below message:
W/element - more than one element found for locator by.css_shadowroot("downloads-manager::sr div") - the first result will be used
below is my xpath:
browser.element(by.css_shadowroot('downloads-manager::sr div:nth-child(1)::sr downloads-item::sr div::sr downloads-item')).getText();
could someone guide me over this? Thanks in advance
[image]<https://user-images.githubusercontent.com/58770415/100961235-336c0280-34df-11eb-9618-1f24ffcd62a0.png>
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub<#4367 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AORWPO6XNK7RUWPVHCWKBCTSS4DH5ANCNFSM4DR44ABQ>.
|
Hi,
Try removing the ::sr in the element locator since it’s outside the Shadow Root.
Use any of these 2 element locators and see whether it’s working or not.
await browser.element(by.css_shadowroot('d2l-navigation d2l-navigation-main-header:nth-type-of(3)'))
OR
await browser.element(by.css_shadowroot('d2l-navigation d2l-navigation-main-header div. d2l-navigation-header-right’))
Thanks,
Alagappan A
From: shopmujahid <notifications@github.com>
Sent: Wednesday, December 9, 2020 12:09 PM
To: angular/protractor <protractor@noreply.github.com>
Cc: Alagappan Annamalai <alagappan.annamalai@riversand.com>; Comment <comment@noreply.github.com>
Subject: Re: [angular/protractor] ShadowDOM support request (#4367)
I'm trying to access one of div elements inside shadow dom both nth-child() and type-of() are not working in my case.
anybody faced this issue before?
Below is the DOM structure and my xpath
[2134234]<https://user-images.githubusercontent.com/58770415/101593797-cc9e8b80-39ad-11eb-8fd0-a7cd7541773f.jpg>
await browser.element(by.css_shadowroot('d2l-navigation::sr d2l-navigation-main-header:nth-type-of(3)'))
I'm receiving no element found error.
Any help would be greatly appreciated Thanks in advance.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub<#4367 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AORWPO7CSSI7P5GH37O74R3ST4LO5ANCNFSM4DR44ABQ>.
|
Thanks @alagappan-annamalai! 👍 the second solution worked for me by removing ::sr and adding tagname.classname, however I ran into other weird issue its not accessing the child elements below: I need to access highlighted element above tried with both xpaths below: and browser.element(by.css_sr('d2l-navigation d2l-navigation-main-header div.d2l-navigation-header-right div d2l-dropdown d2l-dropdown-content div div div div ul li.<entire class name>')) (the li class name will append some text to it when we hover over it) I'm receiving no element found error. |
This can be handled in a simple way itself without css_sr and providing few HTML web elements |
Bravo, worked like a charm Thanks @alagappan-annamalai ! 👍 |
Trying to click a button which is inside an iframe and the iframe is inside #shadow-root, but everytime the automation runs, getting #shadow-root (closed) and not able to switch the frame or access it's element. I am using this in Protractor. |
@Rituparna2021 any progress? |
@lexigren as you might have seen in this RFC, Protractor is being discontinued and it is unlikely that this feature request will be implement. I recommend to take a look into WebdriverIO which supports shadow DOM. We have created a migration guide using a codemod to transition to WebdriverIO in an automated fashion. Let me know if you have any questions. |
@christian-bromann |
Hello @alagappan-qa I´m new to protractor and also a beginner programmer so basically a complete beginner and I wanted to ask you where exactly would you implement this workaround in an e2e unit-test with angular. I tried the protractor.conf.js under the onPrepare() Method as you recommended but I get lots of errors there.... Thanks and greetings |
When combined with Angular's ShadowDom View Encapsulation, elements inside the shadowroot always return StaleElementReferenceError. |
Hi, i m new to protractor just wanted to get multiple shadow root elements, I came across the avobe scripts but was not able to understand where to place the scripts and call. It will be a great help. |
I have implemented it and documented how to do it on my medium article here
|
Seems that ShadowDOM support is still missing:
Background
I am working with some Polymer 2 components which implements ShadowDOM v1 spec and I need to select elements inside their
shadowRoot
s to run e2e tests.deepCss
might be a solution but it doesn't work for me. As far as I can see,by.deepCss
is nothing special difference withby.css
but appending* /deep/
at the beginning of the given CSS selector, however,/deep/
seems deprecated on the browser.I am working with the following versions:
v6.10.3
v5.1.2
v4.2.4
Chrome
Ubuntu v16.04.2 AMD64 LTS Xenial
I think I checked all relevant articles including the followings and I couldn't get any satisfied answer:
Workaround
Anyway, I can select inner elements of ShadowDOM elements by adding a custom locator. Here is my workaround:
Conclusion
Since the workaround works on my side, so I am asking~ is there anything I missed or I misused the background principle of Protractor in my workaround? I am politely saying ... if I don't violate your certain rules too much, is it possible to add ShadowDOM support something like that into the next update of Protractor?
Thank you.
The text was updated successfully, but these errors were encountered: