Skip to content

find: first/last cannot be used as modifiers after role/text locators #364

@grantlovell

Description

@grantlovell

Description

The find command's first/last keywords are locator types rather than modifiers, which means they cannot be chained after other locators like role. This leads to confusing validation errors when users intuitively try to combine them.

Reproduction

agent-browser find role spinbutton first fill '20'

Error:

✗ Validation error: name: Expected string, received null, subaction: Invalid enum value. Expected 'click' | 'fill' | 'check' | 'hover', received 'first'

Expected Behavior

Either:

  1. Support first/last as modifiers after any locator type: find role spinbutton first fill '20'
  2. Provide a clear error message like: "first" is a locator type, not a modifier. Use: find first "[role=spinbutton]" fill '20'

Current Workaround

Use CSS attribute selectors with first/last as the locator type:

agent-browser find first "[role=spinbutton]" fill "20"

Analysis

In cli/src/commands.rs, parse_find() treats position 2 (rest.get(2)) as the subaction unconditionally:

let subaction = rest.get(2).unwrap_or(&"click");

When first occupies that position, it gets passed as the subaction to the daemon's Zod schema which expects one of click | fill | check | hover.

Suggestion

The simplest improvement would be better error messaging. A more ambitious change would allow first/last/nth to work as post-locator modifiers by detecting them in the subaction position and restructuring the command accordingly.

Version: 0.8.3

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