@@ -2776,32 +2776,47 @@ class Playwright extends Helper {
27762776 . locator ( `${ locator . isCustom ( ) ? `${ locator . type } =${ locator . value } ` : locator . simplify ( ) } >> text=${ text } ` )
27772777 . first ( )
27782778 . waitFor ( { timeout : waitTimeout , state : 'visible' } )
2779+ . catch ( e => {
2780+ throw new Error ( errorMessage )
2781+ } )
27792782 }
27802783
27812784 if ( locator . isXPath ( ) ) {
2782- return contextObject . waitForFunction (
2783- ( [ locator , text , $XPath ] ) => {
2784- eval ( $XPath )
2785- const el = $XPath ( null , locator )
2786- if ( ! el . length ) return false
2787- return el [ 0 ] . innerText . indexOf ( text ) > - 1
2788- } ,
2789- [ locator . value , text , $XPath . toString ( ) ] ,
2790- { timeout : waitTimeout } ,
2791- )
2785+ return contextObject
2786+ . waitForFunction (
2787+ ( [ locator , text , $XPath ] ) => {
2788+ eval ( $XPath )
2789+ const el = $XPath ( null , locator )
2790+ if ( ! el . length ) return false
2791+ return el [ 0 ] . innerText . indexOf ( text ) > - 1
2792+ } ,
2793+ [ locator . value , text , $XPath . toString ( ) ] ,
2794+ { timeout : waitTimeout } ,
2795+ )
2796+ . catch ( e => {
2797+ throw new Error ( errorMessage )
2798+ } )
27922799 }
27932800 } catch ( e ) {
27942801 throw new Error ( `${ errorMessage } \n${ e . message } ` )
27952802 }
27962803 }
27972804
27982805 // Use a simple Promise.race with two complementary strategies:
2799- // 1. page.waitForFunction - checks document.body.innerText (broad search)
2806+ // 1. page.waitForFunction - checks entire document text content including title, body, etc.
28002807 // 2. contextObject.locator with :has-text - uses Playwright's native text matching
28012808 // Both approaches will wait for the full timeout duration
28022809 return Promise . race ( [
2803- // Strategy 1: Check document body innerText
2804- this . page . waitForFunction ( text => document . body && document . body . innerText . indexOf ( text ) > - 1 , text , { timeout : waitTimeout } ) ,
2810+ // Strategy 1: Check entire document text content (including title)
2811+ this . page . waitForFunction (
2812+ text => {
2813+ // Check document text content - includes title and all visible text
2814+ const documentText = document . documentElement . innerText || document . documentElement . textContent || ''
2815+ return documentText . indexOf ( text ) > - 1
2816+ } ,
2817+ text ,
2818+ { timeout : waitTimeout } ,
2819+ ) ,
28052820 // Strategy 2: Use Playwright's native text locator
28062821 contextObject
28072822 . locator ( `:has-text(${ JSON . stringify ( text ) } )` )
0 commit comments