Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why isn't my locator finding this element? #21808

Closed
hornta opened this issue Mar 20, 2023 · 1 comment · Fixed by #22124
Closed

Why isn't my locator finding this element? #21808

hornta opened this issue Mar 20, 2023 · 1 comment · Fixed by #22124
Assignees
Labels

Comments

@hornta
Copy link

hornta commented Mar 20, 2023

I got this label and button. I do expect myself to target this combobox using the locator below but for some reason playwright can't find it. When I open the inspect window and record myself clicking on the element it gives me a locator like so:
locator("#floating-ui-2335").

I can even see the accesibility pane in Chrome that the name of the element is ABC and that it comes from the associcated label.

<label for="floating-ui-2335">ABC</label>
<button 
  id="floating-ui-2335" 
  type="button" 
  aria-expanded="false" 
  aria-haspopup="listbox" 
  aria-controls="floating-ui-2340" 
  role="combobox" 
  aria-invalid="false" 
  value="" 
  name="organizationalUnits"
>...</button>
// test
await page.locator('role=combobox[name="ABC"]').click();

References:
dequelabs/axe-core#3353
w3c/html-aria#396

@hornta hornta changed the title Why isn't my selector finding this element? Why isn't my locator finding this element? Mar 20, 2023
@aslushnikov
Copy link
Contributor

I can reproduce with the following test:

import { test, expect } from '@playwright/test';

test('test', async ({ page }) => {
  await page.setContent(`
    <label for="btn">ABC</label>
    <button id="btn" role="combobox">button</button>
  `);
  await page.getByRole('combobox', { name: 'ABC' }).click();
});

The accessibility panel for the button, indeed, shows that Accessible name is "ABC".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants