Skip to content

[browser mode] Calling .click() or another interaction function on a locator that resolves to more than one element should error #9578

@julienw

Description

@julienw

Describe the bug

It's common that locators can resolve to several elements. When calling element() on it, it errors accordingly, providing a useful feedback to the user.

However when using an interaction method instead, vitest doesn't error. This can be confusing to the developer, by interacting with an unexpected control.

Reproduction

See the testcase in https://github.com/julienw/vitest-multiple-results-issue
Run:

npm i
npm test

Notice that the second test fails. The test checks that .click() errors.

System Info

System:
    OS: Linux 6.12 Debian GNU/Linux 13 (trixie) 13 (trixie)
    CPU: (16) x64 11th Gen Intel(R) Core(TM) i9-11900H @ 2.50GHz
    Memory: 37.99 GB / 62.53 GB
    Container: Yes
    Shell: 5.2.37 - /bin/bash
  Binaries:
    Node: 24.12.0 - /home/julien/.nvm/versions/node/v24.12.0/bin/node
    Yarn: 1.22.22 - /usr/bin/yarn
    npm: 11.6.2 - /home/julien/.nvm/versions/node/v24.12.0/bin/npm
    pnpm: 10.9.0 - /home/julien/.local/share/pnpm/pnpm
    bun: 1.0.29 - /home/julien/.bun/bin/bun
    Deno: 2.0.0 - /home/julien/.cargo/bin/deno
  Browsers:
    Chrome: 144.0.7559.109
    Chromium: 144.0.7559.96
    Firefox: 140.7.0esr
    Firefox Developer Edition: 140.7.0esr
  npmPackages:
    @vitejs/plugin-react: ^5.1.3 => 5.1.3 
    @vitest/browser: ^4.0.18 => 4.0.18 
    @vitest/browser-webdriverio: ^4.0.18 => 4.0.18 
    vite: ^7.3.1 => 7.3.1 
    vitest: ^4.0.18 => 4.0.18 
    vitest-browser-react: ^2.0.5 => 2.0.5

Used Package Manager

npm

Validations

Metadata

Metadata

Assignees

Labels

p3-minor-bugAn edge case that only affects very specific usage (priority)webdriverio

Type

Projects

Status

Approved

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions