diff --git a/packages/playwright-core/src/utils/isomorphic/stringUtils.ts b/packages/playwright-core/src/utils/isomorphic/stringUtils.ts index f060eeb658423..f642e5cc8c7be 100644 --- a/packages/playwright-core/src/utils/isomorphic/stringUtils.ts +++ b/packages/playwright-core/src/utils/isomorphic/stringUtils.ts @@ -68,7 +68,7 @@ export function escapeForTextSelector(text: string | RegExp, exact: boolean, cas if (exact) return '"' + text.replace(/["]/g, '\\"') + '"'; if (text.includes('"') || text.includes('>>') || text[0] === '/') - return `/${escapeForRegex(text).replace(/\s+/, '\\s+')}/` + (caseSensitive ? '' : 'i'); + return `/${escapeForRegex(text).replace(/\s+/g, '\\s+')}/` + (caseSensitive ? '' : 'i'); return text; } diff --git a/tests/page/selectors-get-by.spec.ts b/tests/page/selectors-get-by.spec.ts index 63510c10074f2..dba79785921fc 100644 --- a/tests/page/selectors-get-by.spec.ts +++ b/tests/page/selectors-get-by.spec.ts @@ -108,29 +108,31 @@ it('getByTitle should work', async ({ page }) => { }); it('getBy escaping', async ({ page }) => { - await page.setContent(`