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
Appends Playwright's locator.visible() (1.63+) to locators, so actions
match only visible elements. Resolved per step: stepOpts({ visibleLocator })
overrides the helper config, following exact/strictMode/elementIndex.
seeElementInDOM, dontSeeElementInDOM and seeNumberOfElements opt out by
setting the step option, since they assert DOM presence regardless of
visibility.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01D6RydiYkagn6C8Pts2Leou
Copy file name to clipboardExpand all lines: docs/helpers/Playwright.md
+6-2Lines changed: 6 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -78,8 +78,9 @@ Type: [object][6]
78
78
*`ignoreHTTPSErrors`**[boolean][27]?** Allows access to untrustworthy pages, e.g. to a page with an expired certificate. Default value is `false`
79
79
*`bypassCSP`**[boolean][27]?** bypass Content Security Policy or CSP
80
80
*`highlightElement`**[boolean][27]?** highlight the interacting elements. Default: false. Note: only activate under verbose mode (--verbose).
81
+
*`visibleLocator`**[boolean][27]?** append [`visible()`][49] to locators, so only visible elements are matched. Requires Playwright 1.63 or newer. Switch it off for a single step with `stepOpts({ visibleLocator: false })`. Not applied to `dragAndDrop`, which passes selectors to Playwright directly, nor to `seeElementInDOM`, `dontSeeElementInDOM` and `seeNumberOfElements`, which check the DOM regardless of visibility. When enabled, a locator matching only hidden elements fails as "element not found" instead of timing out on actionability, `strict` mode ignores hidden duplicates, and elements hidden by CSS (like a custom checkbox built on a visually hidden `input`) are no longer found.
81
82
*`recordHar`**[object][6]?** record HAR and will be saved to `output/har`. See more of [HAR options][3].
82
-
*`testIdAttribute`**[string][9]?** locate elements based on the testIdAttribute. See more of [locate by test id][49].
83
+
*`testIdAttribute`**[string][9]?** locate elements based on the testIdAttribute. See more of [locate by test id][50].
83
84
*`storageState`**([string][9] | [object][6])?** Playwright storage state (path to JSON file or object)
84
85
passed directly to `browser.newContext`.
85
86
If a Scenario is declared with a `cookies` option (e.g. `Scenario('name', { cookies: [...] }, fn)`),
@@ -97,6 +98,7 @@ Returns elements array if role locator, null otherwise
* @prop {boolean} [highlightElement] - highlight the interacting elements. Default: false. Note: only activate under verbose mode (--verbose).
104
+
* @prop {boolean} [visibleLocator=false] - append [`visible()`](https://playwright.dev/docs/api/class-locator#locator-visible) to locators, so only visible elements are matched. Requires Playwright 1.63 or newer. Switch it off for a single step with `stepOpts({ visibleLocator: false })`. Not applied to `dragAndDrop`, which passes selectors to Playwright directly, nor to `seeElementInDOM`, `dontSeeElementInDOM` and `seeNumberOfElements`, which check the DOM regardless of visibility. When enabled, a locator matching only hidden elements fails as "element not found" instead of timing out on actionability, `strict` mode ignores hidden duplicates, and elements hidden by CSS (like a custom checkbox built on a visually hidden `input`) are no longer found.
104
105
* @prop {object} [recordHar] - record HAR and will be saved to `output/har`. See more of [HAR options](https://playwright.dev/docs/api/class-browser#browser-new-context-option-record-har).
105
106
* @prop {string} [testIdAttribute=data-testid] - locate elements based on the testIdAttribute. See more of [locate by test id](https://playwright.dev/docs/locators#locate-by-test-id).
106
107
* @prop {string|object} [storageState] - Playwright storage state (path to JSON file or object)
@@ -398,6 +399,7 @@ class Playwright extends Helper {
398
399
storageState: undefined,
399
400
onResponse: null,
400
401
strict: false,
402
+
visibleLocator: false,
401
403
}
402
404
403
405
process.env.testIdAttribute='data-testid'
@@ -2008,6 +2010,7 @@ class Playwright extends Helper {
2008
2010
* {{> seeElementInDOM }}
2009
2011
*/
2010
2012
asyncseeElementInDOM(locator){
2013
+
disableVisibleLocatorForStep()
2011
2014
constels=awaitthis._locate(locator)
2012
2015
try{
2013
2016
returnempty('elements on page').negate(els.filter(v=>v).fill('ELEMENT'))
@@ -2020,6 +2023,7 @@ class Playwright extends Helper {
2020
2023
* {{> dontSeeElementInDOM }}
2021
2024
*/
2022
2025
asyncdontSeeElementInDOM(locator){
2026
+
disableVisibleLocatorForStep()
2023
2027
constels=awaitthis._locate(locator)
2024
2028
try{
2025
2029
returnempty('elements on a page').assert(els.filter(v=>v).fill('ELEMENT'))
@@ -2397,11 +2401,12 @@ class Playwright extends Helper {
0 commit comments