microsoft / microsoft/playwright

[Bug]: getByRole() with a regex name and a string description prints the raw internal:role selector

Open
#42,779 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
96.3k
Forks
6.5k
Avg merge
1d 6h
Merged PRs (30d)
180

Description

### Version

1.61.0 and later, still on main

### Steps to reproduce

```js
test('repro', async ({ page }) => {
console.log(`${page.getByRole('button', { name: /Delete/i, description: 'Removes the item' })}`);
console.log(`${page.getByRole('row', { name: 'Order 42', description: /shipped/ })}`);
});
```

### Expected behavior

```
getByRole('button', { name: /Delete/i, description: 'Removes the item' })
getByRole('row', { name: 'Order 42', description: /shipped/ })
```

### Actual behavior

```
internal:role=button[name=/Delete/i][description="Removes the item"i]
internal:role=row[name="Order 42"i][description=/shipped/]
```

The locator still matches, but this raw selector is what shows up in the `Locator:` line of expect errors and in `waiting for` call logs. Python, Java and .NET print it raw too. Two regexes or two strings print fine.

### Additional context

It comes from the exactness check added in #41035. A regex is parsed as case sensitive, so next to a string that isn't exact it counts as a conflict. I'd be happy to send a fix.

### Environment

macOS, Node 25.6.1, Playwright main at ebf3a87

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the exactness check introduced in #41035 and the getByRole locator serialization exercised by the reproduction. Compare the output for mixed regex and string name or description values with the expected public getByRole strings, then add regression coverage showing the raw internal selector is no longer printed.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
testing
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
72/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.