diff --git a/packages/playwright-core/src/client/locator.ts b/packages/playwright-core/src/client/locator.ts index 9d805b3cfa..a77fd56f34 100644 --- a/packages/playwright-core/src/client/locator.ts +++ b/packages/playwright-core/src/client/locator.ts @@ -42,7 +42,7 @@ export class Locator implements api.Locator { if (options?.hasText) { const text = options.hasText; if (isRegExp(text)) - this._selector += ` >> :scope:text-matches(${escapeWithQuotes(text.source, '"')}, "${text.flags}")`; + this._selector += ` >> has=${JSON.stringify('text=' + text.toString())}`; else this._selector += ` >> :scope:has-text(${escapeWithQuotes(text, '"')})`; } diff --git a/tests/page/locator-query.spec.ts b/tests/page/locator-query.spec.ts index fc5194b97d..29742c1531 100644 --- a/tests/page/locator-query.spec.ts +++ b/tests/page/locator-query.spec.ts @@ -92,11 +92,22 @@ it('should filter by regex and regexp flags', async ({ page }) => { it('should filter by case-insensitive regex in a child', async ({ page }) => { it.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/15348' }); - it.fixme(); await page.setContent(`
Title Text
`); await expect(page.locator('div', { hasText: /^title text$/i })).toHaveText('Title Text'); }); +it('should filter by case-insensitive regex in multiple children', async ({ page }) => { + it.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/15348' }); + await page.setContent(`
Title

Text

`); + await expect(page.locator('div', { hasText: /^title text$/i })).toHaveClass('test'); +}); + +it('should filter by regex with special symbols', async ({ page }) => { + it.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/15348' }); + await page.setContent(`
First/"and"

Second\\

`); + await expect(page.locator('div', { hasText: /^first\/".*"second\\$/si })).toHaveClass('test'); +}); + it('should support has:locator', async ({ page, trace }) => { it.skip(trace === 'on');