kryptar

how to use if with wingettext

11 posts in this topic

some programs i run now automated with autoit, one opens does its stuff closes another opens so on and so forth. currently i estimate run times and have sleep times to close and open.

what i would like to achieve is using a wingettext and an if statement to check if program is finished then close and start new one.

for instance the window in question shows IDLE as text when not running and WORKING when it is, these text statements show as visible text in the autoit window info tool so i figure i should be able to look to see if it says IDLE then say If "IDLE" Then do this, then loop the gettext until proper response is met.

Share this post


Link to post
Share on other sites



thanks for speedy response, worked perfectly

i am almost annoyed at its simplicity its great everything i was trying was 4 times longer and crashed

Share this post


Link to post
Share on other sites

If StringInStr(WinGetText("mywindow", ""), "IDLE") Then

Opt("WinTitleMatchMode", 4)

Run("notepad.exe")

ElseIf StringInStr(WinGetText("mywindow", ""), "") Then

Sleep(5000)

EndIf

ok i used this and it did exactly what i wanted, when IDLE exists notepad opens if text anything other than idle it does nothing, my only problem now is to get it to loop and check until IDLE does exist and execute.

Share this post


Link to post
Share on other sites

Not difficult at all - you need to use one of the other functions: While/WEnd or Do/Until.

Here is an example of Do/Until:

Do 
    Sleep(1000)
Until StringInStr(WinGetText("my window", ""), "IDLE")

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Share this post


Link to post
Share on other sites

i must be missing something, i set script out like this, which will open notepad if idle is present but not keep looking and wait for it to appear.

i tried moving the Endif to after the until thinking that would solve that problem but that just returns a syntax no endif present and wont run.

Do

If StringInStr(WinGetText("mywindow", ""), "IDLE") Then

Opt("WinTitleMatchMode", 4)

Run("notepad.exe")

ElseIf StringInStr(WinGetText("mywindow", ""), "") Then

EndIf

Sleep(2000)

Until StringInStr(WinGetText("mywindow", ""), "IDLE")

Share this post


Link to post
Share on other sites

Hmmm - did I mentioned that you need to think a little bit for yourself too? ;)

The code I gave you last time (Do/Until) what do you think it does?

....

....

....

:)

It checks every second to see if the text of your window contains "IDLE"

- if it does NOT contain IDLE then sleeps for 1 sec then checks again

- if the text does contain IDLE then exits the Do/Until loop

This is a basic example of a waiting loop.

So ... The code should be like this:

Do
    Sleep(1000)
Until StringInStr(WinGetText("mywindow", ""), "IDLE")
Opt("WinTitleMatchMode", 4)
Run("notepad.exe")

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

Hi, I am doing automation testing. I need to open the application and need to check whether the application is accessible or not. But I can validate the application using window title but need to validate the application using a word in the window. I tried WinWaitActive command but its not working, even i tried WinGetText command with IF condition. Kindly suggest me the way forward.

Application content: I need to fetch the word "PASSED" from application.

 <?xml version="1.0" encoding="utf-8" ?>

<result>PASSED</result>
<reason>Successful result. Response code: OK</reason>
</Result>

Code:

Func AutoLoginSIT_Prosource2()
$application_Name ="SIT_One Ops_Prosource2" 
$oIE = _IECreate ("http://10.187.20.216/DGSTesterWS/DGSTesterService.asmx/scanAddressLightTester")
$HWND = _IEPropertyGet($oIE, "HWnd")
WinSetState ($HWND , "", @SW_MAXIMIZE)
WinWait("10.187.20.216", "PASSED",5)
If WinActive("10.187.20.216", "PASSED")Then
 $Status ="Success"
 
Else
 $Status="Failure"
 
EndIf

WrtApplNameToxl($application_Name,$Status,$i)

;Closing the window
If WinActivate($oIE) Then
WinClose($oIE)
EndIf
EndFunc

Edited by Automationhc
Typo mistake

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

Hello Automationhc,

Welcome to the forums. In the future, you should start a new thread rather than necropost an old one. I believe there is a better way to perform your testing. There are UDFs posted in the examples section for performing WinHTTP calls as well as dealing with XML data. I suggest that you research those and then start a new thread with any questions that you may have.

Regards, Dan

Edited by Danp2

Share this post


Link to post
Share on other sites

Hi Dan,

Thank you so much. Will check.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now