Home > Language Reference > Wait Functions > Wait for a Text

Wait for a Text

The Pause until text pauses script execution until the specified text is displayed in the specified window. If after the specified timeout, the pause condition is not met, the block of statements following PauseFalse keyword is executed.

 Video: How to use Text Synchronization

Usage

Used to wait for an update in the application when no new window tells that the update has been done. For example, in a terminal emulation software, if you press Enter, the text within the emulation window changes but it is still the same window and so you could use Pause until some new text is there to detect the new screen. Use Recording mode or Insert/Synchronization on text menu to generate easily such a Pause.

Syntax

Pause [x secs|x ticks] until
    Text(<Text>)
    InWindow(<window_name>,<instance>)|InWindowAnyInstance((<window_name>)
    [InArea(<x>,<y>,<height>,<width>)]
[PauseOK|PauseTrue]
 'If the condition is met, the optional statements after the PauseOK and before the PauseFalse are executed
[PauseFalse]
' After the specified timeout, if the condition is not met, the statements after the PauseFalse are executed
     MsgBox("Pause at line "+ #ErrorLine$ +" has failed !",16,"Runtime error")
     End
EndPause

Parameters

[x secs|x ticks], optional. If the pause condition is not met after x seconds or x ticks (a tick is around 1/100 sec), the statements after the PauseFalse keyword are executed. If not specified, the default timeout is the one as defined by #PauseTimeout system variable (default value: 120 seconds). mins can be used instead of secs for a timeout in minutes. 

Text, keyword, specifies the <Text> to wait for.

InWindow|InWindowAnyInstance, keyword. It specifies the <window_name> of the window where to search the <text>. <instance> is not specified if InWindowAnyInstance is used (then the text found in the specified window whatever its instance will trigger).

InArea, optional keyword. It specifies the area as defined by coordinates <x>,<y>,<height>,<width> where to look for the <text>. If not specified, the <text> is searched in the whole <window_name>.

Remarks

If the text to search is in a new window, prefer UseWindow function to wait for this new window (and so new text in this new window). Do not use a Pause until text to detect that a web page has finished to load, a UsePage is enough. Note too that within Internet Explorer, only a pause until OCR text can be used.

See also

Wait for a Date
Wait for Image
Wait for a Keystroke
Wait for a Menu Selection
Wait for a Mouse Click
Wait for OCR Text
Wait for a Time Delay
Wait for a Window

Example

'Wait until a text typed is there.
Shell("notepad",1)
UseWindow("NOTEPAD.EXE|Edit|Untitled - Notepad|1",1)
 SendKeys("Hello Tester")
'Wait until Tester word is detected
Pause 10 secs until
   Text("Tester")
   InWindow("NOTEPAD.EXE|Edit|Untitled - Notepad|1",1)
PauseFalse
   MsgBox("'Wait for' at line " + #ErrorLine$ + " has failed !")
   End
EndPause
CloseWindow("NOTEPAD.EXE|Notepad|Untitled - Notepad",1)
UseWindow("NOTEPAD.EXE|CtrlNotifySink|Notepad|8",1)
 Click(Button,"Do&n't Save")