Fix frame-aware element extraction and click handling#8
Closed
yifeizhou980429 wants to merge 1 commit into
Closed
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
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.
Changes in this PR
Add frame metadata to InteractiveElement
Added a frame field to InteractiveElement
Default is "main" for main-document elements
Make element extraction frame-aware
Updated extract_elements() to iterate over all frames, not just the main page
Each frame now runs element extraction separately
Frame metadata is passed into the extraction script and stored on each element
Preserve iframe coordinates relative to the top page
Added frame offset calculation so element coordinates from iframes are normalized relative to the top-level page
This keeps element positions aligned with top-page screenshots / visual reasoning
Avoid cross-frame index collisions
Reindexed extracted elements globally after aggregation
This prevents duplicate element indices across main page and iframe contexts
Make click handling use frame-aware locators
Updated click() to use frame-aware locator resolution
If the element belongs to the main page, it uses page.locator(...)
If the element belongs to an iframe, it resolves the correct frame and uses frame.locator(...)
Add safe fallback for missing frame metadata
click() now safely defaults missing frame info to "main"
This keeps the main-page interaction path robust even when frame metadata is absent
This fix makes browser interactions much more reliable for real-world pages that contain embedded frames.
Without this change:
iframe inputs may be matched but not clicked/focused correctly
typing may go to the wrong focus target
page-level keyboard events can happen instead of field input
With this change:
main-page and iframe inputs can both be selected and clicked correctly
focus is established on the intended target more reliably
typing is more likely to go into the correct field