-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add new locator type for Shadow Root elements #7905
Conversation
4426fff
to
0bd7885
Compare
7284bb5
to
b9f198e
Compare
b9f198e
to
d35701f
Compare
import static org.openqa.selenium.testing.drivers.Browser.MARIONETTE; | ||
|
||
/** | ||
* Shadow Root is not supported by Firefox. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shadow-DOM is supported in Firefox https://developer.mozilla.org/en-US/docs/Web/API/ShadowRoot#Browser_compatibility
But calling "element.shadowRoot" will return the map of different attributes, so you cannot cast it to WebElement but must directly search inside it by "shadowRoot.querySelector()"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense, and it's possible.
But to get the selector out of By
, I would have to use a toString()
and remove the prefix By.cssSelector:
manually, which may cause issues later if toString()
is changed to something else.
A better option would be to add a method to By
class to get only the selector.
I will make some changes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dstekanov Please take a look on the new implementation.
ddf95ac
to
3c616af
Compare
3a477a0
to
754cafb
Compare
Closing this to consolidate on #5869 |
Description
Adds support to locate elements that have Shadow Roots.
Adds new annotation
@FindShadowBy
, which can be used to locate and elements that are inside a Shadow Root.Adds a helper class
ShadowElementFinder
, which can be used to verify if an element has a Shadow Root attached to it.Motivation and Context
Right now Selenium doesn't support PageObject annotations in elements that have Shadow Root.
The current approach:
New implementation allows:
As in
@FindBy
, it also allows to retrieve lists:If nested Shadow Roots are present, the same will work, the only thing that needs to be provided is the selector for each Shadow Root in the correct order that they are nested:
Notes
The elements returned by the last
@FindBy
won't have their shadow roots extracted automatically, this is to allow the user to use methods such asgetAttribute
, which would throw an error if inside the shadow root. If the user wants to extract it,ShadowElementFinder
can be used to do so.This also means that providing just one locator to
@FindShadowBy
will yield the same result as using@FindBy
, which is not a concern.Once inside a Shadow Root, it's not possible to use xpath selector.
I didn't add any validations to
FindShadowBy
as this could limit the usage of the chain selectors, and Selenium already throws an exception if the user tries to use an invalid selector type.Types of changes
Checklist