Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

fix(mcp): anchor aria-ref regex in target resolution (#40610)

Yury Semikhatsky7579e1b34c2d
diff --git a/CLAUDE.md b/CLAUDE.md
index 76da6a4b9c..a8034c3343 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -139,6 +139,8 @@ Never add "Generated with" in commit message.
Never add test plan to PR description. Keep PR description short — a few bullet points at most.
Branch naming for issue fixes: `fix-<issue-number>`
+**Never amend commits.** Always create a new commit for follow-up changes, even when iterating on an open PR. Amending rewrites history and forces a force-push, losing the incremental review trail. Only amend if the user explicitly says so.
+
**Never `git push` without an explicit instruction to push.** Applies even when a PR is already open for the branch — additional commits are immediately visible to reviewers. Commit locally, report what was committed, and wait. Only push when the user's message contains "push", "upload", "create PR", "ship it", or equivalent.
## Development Guides
diff --git a/packages/playwright-core/src/tools/backend/tab.ts b/packages/playwright-core/src/tools/backend/tab.ts
index 55d49715c0..0fac1073be 100644
--- a/packages/playwright-core/src/tools/backend/tab.ts
+++ b/packages/playwright-core/src/tools/backend/tab.ts
@@ -444,7 +444,7 @@ export class Tab extends EventEmitter<TabEventsInterface> {
async targetLocators(params: { element?: string, target: string }[]): Promise<{ locator: playwright.Locator, resolved: string }[]> {
await this._initializedPromise;
return Promise.all(params.map(async param => {
- if (!param.target.match(/(f\d+)?(e\d+)/)) {
+ if (!param.target.match(/^(f\d+)?e\d+$/)) {
const selector = locatorOrSelectorAsSelector('javascript', param.target, this.context.config.testIdAttribute || 'data-testid');
const handle = await this.page.$(selector);
if (!handle)
diff --git a/tests/mcp/click.spec.ts b/tests/mcp/click.spec.ts
index dcb7acf156..67b950fa05 100644
--- a/tests/mcp/click.spec.ts
+++ b/tests/mcp/click.spec.ts
@@ -202,3 +202,25 @@ test('browser_click (test id attribute)', async ({ startClient, server, mcpBrows
code: `await page.getByTestId('submit').click();`,
});
});
+
+test('browser_click (locator target containing aria-ref-like substring)', async ({ client, server }) => {
+ server.setContent('/', `
+ <title>Title</title>
+ <button id="z2l9e43l3">Submit</button>
+ `, 'text/html');
+
+ await client.callTool({
+ name: 'browser_navigate',
+ arguments: { url: server.PREFIX },
+ });
+
+ expect(await client.callTool({
+ name: 'browser_click',
+ arguments: {
+ element: 'Submit button',
+ target: '#z2l9e43l3',
+ },
+ })).toHaveResponse({
+ code: `await page.locator('#z2l9e43l3').click();`,
+ });
+});