Skip to content

find role link generates wrong CSS selector — matches <link> instead of <a> #1123

@alahawash

Description

@alahawash

Bug

find role link click --name "X" --exact fails to find <a> anchor elements because the generated CSS selector queries <link> (stylesheet) elements instead of <a> tags.

Root cause

In handle_getbyrole (cli/src/native/actions.rs), the JavaScript query is:

const els = document.querySelectorAll('[role="link"], link');

The CSS selector link matches <link> elements (used in <head> for stylesheets/resources), not <a> anchor elements. The ARIA role link maps to <a> tags.

This means find role link only finds elements with an explicit role="link" attribute and misses all regular <a href="..."> links.

For comparison, button works correctly because <button> is both the ARIA implicit tag and the HTML element name. link is the ARIA role name, but the HTML element is <a>.

Reproduction

# Start agent-browser and navigate to any page with a standard <a> link
agent-browser navigate https://example.com

# This FAILS — finds no element (or matches a <link> stylesheet in <head>)
agent-browser find role link click --name "More information..." --exact

# Workaround using find text works, but is less precise
agent-browser find text "More information..." click --exact

Minimal HTML to reproduce

<html>
<head>
  <link rel="stylesheet" href="style.css">  <!-- this is what the selector matches -->
</head>
<body>
  <table>
    <tr>
      <td>
        <a href="/page">Example Link</a>  <!-- this is what it SHOULD match -->
      </td>
    </tr>
  </table>
</body>
</html>
agent-browser find role link click --name "Example Link" --exact
# Expected: clicks the <a> element
# Actual: "No element found: getByRole('link', { name: 'Example Link', exact: true })"

Expected behavior

The query should use a instead of link:

const els = document.querySelectorAll('[role="link"], a');

More generally, handle_getbyrole should map ARIA roles to their implicit HTML tag, since several roles differ from their element name (e.g. linka, headingh1h6, textboxinput[type="text"], textarea, comboboxselect).

Affected version

Latest (v0.24.0)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions