diff --git a/packages/playwright-core/src/server/supplements/injected/consoleApi.ts b/packages/playwright-core/src/server/supplements/injected/consoleApi.ts index ee050302ad..e5a0613bdb 100644 --- a/packages/playwright-core/src/server/supplements/injected/consoleApi.ts +++ b/packages/playwright-core/src/server/supplements/injected/consoleApi.ts @@ -28,9 +28,10 @@ function createLocator(injectedScript: InjectedScript, initial: string, options? this.selector = selector; if (options?.hasText) { const text = options.hasText; - const matcher = text instanceof RegExp ? 'text-matches' : 'has-text'; - const source = escapeWithQuotes(text instanceof RegExp ? text.source : text, '"'); - this.selector += ` >> :scope:${matcher}(${source})`; + if (text instanceof RegExp) + this.selector += ` >> :scope:text-matches(${escapeWithQuotes(text.source, '"')}, "${text.flags}")`; + else + this.selector += ` >> :scope:has-text(${escapeWithQuotes(text)})`; } const parsed = injectedScript.parseSelector(this.selector); this.element = injectedScript.querySelector(parsed, document, false); diff --git a/tests/inspector/console-api.spec.ts b/tests/inspector/console-api.spec.ts index 84f39a2956..73426ac7f8 100644 --- a/tests/inspector/console-api.spec.ts +++ b/tests/inspector/console-api.spec.ts @@ -54,6 +54,9 @@ it('should support playwright.locator.value', async ({ page }) => { it('should support playwright.locator.values', async ({ page }) => { await page.setContent('