@@ -2476,7 +2476,7 @@ class Playwright extends Helper {
2476
2476
async waitForEnabled ( locator , sec ) {
2477
2477
const waitTimeout = sec ? sec * 1000 : this . options . waitForTimeout
2478
2478
locator = new Locator ( locator , 'css' )
2479
- const matcher = await this . context
2479
+
2480
2480
let waiter
2481
2481
const context = await this . _getContext ( )
2482
2482
if ( ! locator . isXPath ( ) ) {
@@ -2498,6 +2498,34 @@ class Playwright extends Helper {
2498
2498
} )
2499
2499
}
2500
2500
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
+
2501
2529
/**
2502
2530
* {{> waitForValue }}
2503
2531
*/
0 commit comments