diff --git a/lib/locator.js b/lib/locator.js index a2f0ea0a3..b1acb016e 100644 --- a/lib/locator.js +++ b/lib/locator.js @@ -591,13 +591,24 @@ Locator.clickable = { `.//*[@title = ${literal}]`, `.//*[@aria-labelledby = //*[@id][normalize-space(string(.)) = ${literal}]/@id ]`, `.//*[@role='button'][normalize-space(.)=${literal}]`, + `.//*[@role='tab' or @role='link' or @role='menuitem' or @role='menuitemcheckbox' or @role='menuitemradio' or @role='option' or @role='treeitem'][contains(normalize-space(string(.)), ${literal})]`, ]), /** * @param {string} literal * @returns {string} */ - self: literal => `./self::*[contains(normalize-space(string(.)), ${literal}) or contains(normalize-space(@value), ${literal})]`, + self: literal => { + // Narrowest-match: prefer the deepest descendant whose string-value contains the literal. + // Falling back to `self` without the `not(descendant...)` guard would match a container + // whose concatenated text happens to include the literal (e.g. a