Skip to content

Let found elements act on themselves - #18

Merged
arrufat merged 2 commits into
mainfrom
element-methods
Oct 15, 2026
Merged

arrufat merged 2 commits into
mainfrom
element-methods

Conversation

@arrufat

@arrufat arrufat commented Oct 15, 2026

Copy link
Copy Markdown
Collaborator

find_element and interactive_elements now return Elements (AsyncElement from an AsyncSession). Each is still the dict the browser sent, so found[0]["name"] and found[0]["backendNodeId"] keep working, and every tool that takes a backendNodeId is also a method on it:

found = page.find_element(role="button", name="Accept")
if found:
    found[0].click()        # was: page.click(backend_node_id=found[0]["backendNodeId"])

The element methods are generated like the session's, into ElementMethods / AsyncElementMethods: click, fill, hover, press, scroll, select_option, set_checked, markdown, html, tree, screenshot, node_details. They drop the selector, url and timeout parameters, which would aim the call elsewhere or navigate first. The generator refuses a tool that would shadow a dict method.

The first commit only regenerates _methods.py against today's nightly, which had drifted (extract docs, tree's max_bytes).

Also works against the 1.0.0 binary, so it can ship as 1.0.0.post2.

find_element and interactive_elements now return Element objects: still
the dicts the browser sent, with every tool that takes a backendNodeId as
a method aimed at that node, so

    found = page.find_element(role="button", name="Accept")
    found[0].click()

replaces page.click(backend_node_id=found[0]["backendNodeId"]). The
methods are generated like the session's, into ElementMethods and
AsyncElementMethods, without the selector, url and timeout parameters
that would aim them elsewhere.
@arrufat
arrufat merged commit 5358c7d into main Oct 15, 2026
11 checks passed
@arrufat
arrufat deleted the element-methods branch October 15, 2026 11:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant