File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -3576,13 +3576,16 @@ class Playwright extends Helper {
35763576 const locator = new Locator ( context , 'css' )
35773577 try {
35783578 if ( ! locator . isXPath ( ) ) {
3579- return contextObject
3580- . locator ( `${ locator . simplify ( ) } >> text=${ text } ` )
3581- . first ( )
3582- . waitFor ( { timeout : waitTimeout , state : 'visible' } )
3583- . catch ( e => {
3584- throw new Error ( errorMessage )
3585- } )
3579+ const deadline = Date . now ( ) + waitTimeout
3580+ do {
3581+ const els = await this . _locate ( locator )
3582+ for ( const el of els ) {
3583+ const texts = await el . evaluateAll ( nodes => nodes . map ( node => node . innerText ?? node . textContent ) )
3584+ if ( texts . some ( t => typeof t === 'string' && t . includes ( text ) ) ) return
3585+ }
3586+ await new Promise ( resolve => setTimeout ( resolve , 100 ) )
3587+ } while ( Date . now ( ) < deadline )
3588+ throw new Error ( errorMessage )
35863589 }
35873590
35883591 if ( locator . isXPath ( ) ) {
Original file line number Diff line number Diff line change @@ -1678,6 +1678,11 @@ export function tests() {
16781678 await I . see ( 'Dynamic text' )
16791679 } )
16801680
1681+ it ( 'should wait for text in context with locator.at' , async ( ) => {
1682+ await I . amOnPage ( '/dynamic' )
1683+ await I . waitForText ( 'Dynamic text' , 2 , new Locator ( '#text' ) . at ( 1 ) )
1684+ } )
1685+
16811686 it ( 'should fail if no context' , async function ( ) {
16821687 let failed = false
16831688 await I . amOnPage ( '/dynamic' )
You can’t perform that action at this time.
0 commit comments