Skip to content

[Bug]: addLocatorHandler displays incorrect error message #34070

Open
@agg23

Description

Version

1.49.1

Steps to reproduce

  1. Run the following test
test('repro', async ({ page, server }) => {
  await page.setContent(`<html><body><script>setTimeout(() => {document.body.innerHTML = '<div><ul><li>Foo</li></ul><ul><li>Bar</li></ul></div>'}, 100)</script></body></html>`);

  await page.addLocatorHandler(page.locator('ul'), async locator => Promise.resolve());

  await page.locator('ul > li').first().boundingBox();
});
  1. The following error will be thrown
    Error: locator.boundingBox: Error: strict mode violation: locator('ul') resolved to 2 elements:
        1) <ul>…</ul> aka getByRole('list').filter({ hasText: 'Foo' })
        2) <ul>…</ul> aka getByRole('list').filter({ hasText: 'Bar' })

    Call log:
      - waiting for locator('ul > li').first()


      379 |   await page.addLocatorHandler(page.locator('ul'), async locator => Promise.resolve());
      380 |
    > 381 |   await page.locator('ul > li').first().boundingBox();

Expected behavior

The error message should read something like:

Error: page.addLocatorHandler: Error: strict mode violation: locator('ul') resolved to 2 elements:

Actual behavior

The error message instead reads:

Error: locator.boundingBox: Error: strict mode violation: locator('ul') resolved to 2 elements:

Notice that it complains about locator.boundingBox even though that call did not fail.

Additional context

No response

Environment

System:
    OS: Windows 11 10.0.26100
    CPU: (6) x64 Intel(R) Core(TM) i5-9500 CPU @ 3.00GHz
    Memory: 2.76 GB / 15.81 GB
  Binaries:
    Node: 20.17.0 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.22 - ~\AppData\Roaming\npm\yarn.CMD
    npm: 10.8.2 - C:\Program Files\nodejs\npm.CMD
  IDEs:
    VSCode: 1.95.2 - C:\Users\agastineau\AppData\Local\Programs\Microsoft VS Code\bin\code.CMD

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions