diff --git a/packages/playwright-core/src/server/injected/selectorGenerator.ts b/packages/playwright-core/src/server/injected/selectorGenerator.ts index 7e4f51b1b2..eaa330a0e5 100644 --- a/packages/playwright-core/src/server/injected/selectorGenerator.ts +++ b/packages/playwright-core/src/server/injected/selectorGenerator.ts @@ -528,7 +528,7 @@ function suitableTextAlternatives(text: string) { const match = text.match(/^([\d.,]+)[^.,\w]/); const leadingNumberLength = match ? match[1].length : 0; if (leadingNumberLength) { - const alt = text.substring(leadingNumberLength).trimStart(); + const alt = trimWordBoundary(text.substring(leadingNumberLength).trimStart(), 80); result.push({ text: alt, scoreBouns: alt.length <= 30 ? 2 : 1 }); } } @@ -537,7 +537,7 @@ function suitableTextAlternatives(text: string) { const match = text.match(/[^.,\w]([\d.,]+)$/); const trailingNumberLength = match ? match[1].length : 0; if (trailingNumberLength) { - const alt = text.substring(0, text.length - trailingNumberLength).trimEnd(); + const alt = trimWordBoundary(text.substring(0, text.length - trailingNumberLength).trimEnd(), 80); result.push({ text: alt, scoreBouns: alt.length <= 30 ? 2 : 1 }); } }