diff --git a/docs/selectors.md b/docs/selectors.md index 5a2b991ce5..0aa87e2a17 100644 --- a/docs/selectors.md +++ b/docs/selectors.md @@ -72,8 +72,8 @@ XPath engine is equivalent to [`Document.evaluate`](https://developer.mozilla.or ### text Text engine finds an element that contains a text node with passed text. Example: `text=Login`. -- By default, the match is case-insensitive, and ignores leading/trailing whitespace. This means `text= Login` matches ``. -- Text body can be escaped with double quotes for precise matching, insisting on specific whitespace and case. This means `text="Login "` will only match `` with exactly one space after "Login". +- By default, the match is case-insensitive, ignores leading/trailing whitespace and searches for a substring. This means `text= Login` matches ``. +- Text body can be escaped with double quotes for precise matching, insisting on exact match, including specified whitespace and case. This means `text="Login "` will only match `` with exactly one space after "Login". - Text body can also be a JavaScript-like regex wrapped in `/` symbols. This means `text=/^\\s*Login$/i` will match `` with any number of spaces before "Login" and no spaces after. > **NOTE** Malformed selector starting with `"` is automatically transformed to text selector. For example, Playwright converts `page.click('"Login"')` to `page.click('text="Login"')`. diff --git a/src/injected/textSelectorEngine.ts b/src/injected/textSelectorEngine.ts index 4d896d3d59..a2c3863569 100644 --- a/src/injected/textSelectorEngine.ts +++ b/src/injected/textSelectorEngine.ts @@ -79,5 +79,5 @@ function createMatcher(selector: string): Matcher { return text => re.test(text); } selector = selector.trim().toLowerCase(); - return text => text.trim().toLowerCase() === selector; + return text => text.toLowerCase().includes(selector); } diff --git a/test/queryselector.spec.js b/test/queryselector.spec.js index 9dc4732e4f..e8dc1a9087 100644 --- a/test/queryselector.spec.js +++ b/test/queryselector.spec.js @@ -528,11 +528,18 @@ module.exports.describe = function({testRunner, expect, playwright, FFOX, CHROMI await page.setContent(`