@@ -2476,7 +2476,7 @@ class Playwright extends Helper {
24762476 async waitForEnabled ( locator , sec ) {
24772477 const waitTimeout = sec ? sec * 1000 : this . options . waitForTimeout
24782478 locator = new Locator ( locator , 'css' )
2479- const matcher = await this . context
2479+
24802480 let waiter
24812481 const context = await this . _getContext ( )
24822482 if ( ! locator . isXPath ( ) ) {
@@ -2498,6 +2498,34 @@ class Playwright extends Helper {
24982498 } )
24992499 }
25002500
2501+ /**
2502+ * {{> waitForDisabled }}
2503+ */
2504+ async waitForDisabled ( locator , sec ) {
2505+ const waitTimeout = sec ? sec * 1000 : this . options . waitForTimeout
2506+ locator = new Locator ( locator , 'css' )
2507+
2508+ let waiter
2509+ const context = await this . _getContext ( )
2510+ if ( ! locator . isXPath ( ) ) {
2511+ const valueFn = function ( [ locator ] ) {
2512+ return Array . from ( document . querySelectorAll ( locator ) ) . filter ( ( el ) => el . disabled ) . length > 0
2513+ }
2514+ waiter = context . waitForFunction ( valueFn , [ locator . value ] , { timeout : waitTimeout } )
2515+ } else {
2516+ const disabledFn = function ( [ locator , $XPath ] ) {
2517+ eval ( $XPath ) // eslint-disable-line no-eval
2518+ return $XPath ( null , locator ) . filter ( ( el ) => el . disabled ) . length > 0
2519+ }
2520+ waiter = context . waitForFunction ( disabledFn , [ locator . value , $XPath . toString ( ) ] , { timeout : waitTimeout } )
2521+ }
2522+ return waiter . catch ( ( err ) => {
2523+ throw new Error (
2524+ `element (${ locator . toString ( ) } ) is still enabled after ${ waitTimeout / 1000 } sec\n${ err . message } ` ,
2525+ )
2526+ } )
2527+ }
2528+
25012529 /**
25022530 * {{> waitForValue }}
25032531 */
0 commit comments