You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(text selector): normalize whitespace for quoted match (#5049)
This changes quoted text selector like `text="Foo Bar"` to perform
normalized whitespace match.
Most of the time users want to match some string visible on the page,
and that always means normalized whitespace.
We keep the case sensitivity and full-string vs substring difference
between quoted and unquoted matches.
By default, the match is case-insensitive, it ignores leading/trailing whitespace and searches for
29
-
a substring. This means `text= Login` matches `<button>Button loGIN (click me)</button>`.
28
+
Matching is case-insensitive and searches for a substring. This means `text=Login` matches `<button>Button loGIN (click me)</button>`. Matching also normalizes whitespace, for example it turns multiple spaces into one, turns line breaks into spaces and ignores leading and trailing whitespace.
30
29
31
-
Text body can be escaped with single or double quotes for precise matching, insisting on exact match,
32
-
including specified whitespace and case. This means `text="Login "` will only match
33
-
`<button>Login </button>` with exactly one space after "Login". Quoted text follows the usual escaping
34
-
rules, e.g. use `\"` to escape double quote in a double-quoted string: `text="foo\"bar"`.
30
+
Text body can be escaped with single or double quotes for full-string case-sensitive match instead. This means `text="Login"` will match `<button>Login</button>`, but not `<button>Login (click me)</button>` or `<button>login</button>`. Quoted text follows the usual escaping
31
+
rules, e.g. use `\"` to escape double quote in a double-quoted string: `text="foo\"bar"`. Note that quoted match still normalizes whitespace.
35
32
36
33
Text body can also be a JavaScript-like regex wrapped in `/` symbols. This means `text=/^\\s*Login$/i`
37
34
will match `<button> loGIN</button>` with any number of spaces before "Login" and no spaces after.
@@ -156,7 +153,7 @@ The `:text` pseudo-class matches elements that have a text node child with speci
156
153
It is similar to the [text] engine, but can be used in combination with other `css` selector extensions.
157
154
There are a few variations that support different arguments:
158
155
159
-
*`:text("substring")` - Matches when element's text contains "substring" somewhere. Matching is case-insensitive. Matching also normalizes whitespace, for example it turns multiple spaces into one, trusn line breaks into spaces and ignores leading and trailing whitespace.
156
+
*`:text("substring")` - Matches when element's text contains "substring" somewhere. Matching is case-insensitive. Matching also normalizes whitespace, for example it turns multiple spaces into one, turns line breaks into spaces and ignores leading and trailing whitespace.
160
157
*`:text-is("string")` - Matches when element's text equals the "string". Matching is case-insensitive and normalizes whitespace.
161
158
*`button:text("Sign in")` - Text selector may be combined with regular CSS.
162
159
*`:text-matches("[+-]?\\d+")` - Matches text against a regular expression. Note that special characters like back-slash `\`, quotes `"`, square brackets `[]` and more should be escaped. Learn more about [regular expressions](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp).
0 commit comments