-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Add frameLocator
, frameLocator.locator
and locator.contentFrame
#5075
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
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ankur22
commented
Aug 20, 2025
ankur22
commented
Aug 20, 2025
ankur22
commented
Aug 20, 2025
2dcf9c9
to
e4ab9db
Compare
7e9fbf6
to
973a292
Compare
b14b4dd
to
e38c7aa
Compare
8f8245b
to
5be0b4c
Compare
locator.frameLocator
frameLocator
and locator.contentFrame
frameLocator
and locator.contentFrame
frameLocator
, frameLocator.locator
and locator.contentFrame
5976239
to
0929454
Compare
ankur22
commented
Aug 29, 2025
// This is a valid response from waitForSelector. It means that the element | ||
// was either hidden or detached. | ||
if iframeHandle == nil { | ||
return nil, "", errors.New("check if element is visible") |
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.
TODO: Use new visible error from #5111
5a61856
to
51c6ca0
Compare
This new selector in the parser will only be used as a directive to let other parts of the codebase know that we need to enter into a frame which could be from a different origin.
First we need to see if the parsed selector has a directive which calls for a step into an iframe or frame.
Now we can split when we find a directive in the parsed selector. We want to be able to step into the iframe/frame first (beforeFrame) and then continue onto afterFrame.
After we have split the selectors on a frame, we need to rebuild them so that we can use them in the next recursive call.
When we wait for a selector, we need to be able to step into an iframe/frame when a directive in the selector is found. This change performs those steps. It will split the selector, retrieve the document for the iframe/frame and then continue the second selector split after stepping into the iframe/frame.
We need to step into iframe/frame when working with count too. This will split on the frame directive, step into the frame by splitting the selector in two, and using the first split to do the step in. The second split of the selector will be used after stepping into the frame
Since Query is used by isVisible and isHidden, which are part of locator too, we need to step into iframe/frame like we do for count and waitForSelector.
This is the common code that is needed when stepping into the iframe/frame.
This will be extended to add a test with CORS
When a frame is hidden, waitForSelector may return nil response. This is a valid case, but one that we should retry on when it is used internally.
51c6ca0
to
dedb00f
Compare
inancgumus
approved these changes
Sep 5, 2025
AgnesToulet
approved these changes
Sep 5, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What?
This adds a few new APIs. It would have been difficult to implement
frameLocator
on its own without the other two APIs:frameLocator
which allows the user to interact with elements withiniframe
s withlocator
like APIs.locator.contentFrame
which returns aframeLocator
, allowing the user to actually retrieve aframeLocator
to start working with elements from with aniframe
.frameLocator.locator
allowing users to actually select elements in aniframe
.Why?
Working with
locator
like APIs is important for maintainable, less flakey tests. It's also a preferred way of working when interacting withiframe
s in Playwright. We're currently on a drive to improve k6 browser's parity to make migrating from Playwright to k6 easier.Essentially,
locator
andframeLocator
APIs will retrieve the latest version of an element or perform an action on the latest version of an element when such APIs are called. Currently websites are very dynamic and we always want to try to work with the latest version of the DOM when trying to retrieve data or perform actions. Working withpage$
andframe.contentFrame
are currently the only way to interact with elements in aniframe
, but these are flakey since they work with old versions of the DOM.The end result of this implementation also allows us to easily chain selectors. Before we used to have to do (imagine having to navigate to multiple nested
iframe
s):and now we can do:
Checklist
make check
) and all pass.Checklist: Documentation (only for k6 maintainers and if relevant)
Please do not merge this PR until the following items are filled out.
Related PR(s)/Issue(s)
#5032