Skip to content
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

Focused element fix #292

Merged
merged 2 commits into from
Dec 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 16 additions & 9 deletions browsergym/core/src/browsergym/core/observation.py
Original file line number Diff line number Diff line change
Expand Up @@ -555,14 +555,21 @@ def extract_focused_element_bid(page: playwright.sync_api.Page):
# this playwright code will dive through iFrames
frame = page
focused_bid = ""
while frame:
focused_element = frame.evaluate_handle(
extract_focused_element_with_bid_script, BID_ATTR
).as_element()
if focused_element:
frame = focused_element.content_frame()
focused_bid = focused_element.get_attribute(BID_ATTR)
else:
frame = None
try:
while frame:
focused_element = frame.evaluate_handle(
extract_focused_element_with_bid_script, BID_ATTR
).as_element()
if focused_element:
frame = focused_element.content_frame()
focused_bid = focused_element.get_attribute(BID_ATTR)
else:
frame = None
except playwright.sync_api.TimeoutError:
focused_bid = ""

# convert null / None to empty string
if not focused_bid:
focused_bid = ""

return focused_bid
Loading