kryptar Posted July 26, 2011 Posted July 26, 2011 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.
enaiman Posted July 26, 2011 Posted July 26, 2011 Easiest way: If StringInStr(WinGetText("my window", ""), "IDLE") Then ;move to next ElseIf StringInStr(WinGetText("my window", ""), "WORKING") Then ;sleep some EndIf 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 :)
Exit Posted July 26, 2011 Posted July 26, 2011 Or If WinExists("Your Title", "IDLE") Then MsgBox(262144, "", @LF & "IDLE" & @LF, 0) ElseIf WinExists("Your Title", "WORKING") Then MsgBox(262144, "", @LF & "WORKING " & @LF, 0) EndIf App: Au3toCmd UDF: _SingleScript()
kryptar Posted July 26, 2011 Author Posted July 26, 2011 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
kryptar Posted July 27, 2011 Author Posted July 27, 2011 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.
enaiman Posted July 27, 2011 Posted July 27, 2011 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 :)
kryptar Posted July 27, 2011 Author Posted July 27, 2011 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")
enaiman Posted July 27, 2011 Posted July 27, 2011 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 :)
Automationhc Posted May 18, 2015 Posted May 18, 2015 (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 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://prosource.standardbank.co.za/"><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" EndIfWrtApplNameToxl($application_Name,$Status,$i);Closing the windowIf WinActivate($oIE) ThenWinClose($oIE)EndIfEndFunc Edited May 18, 2015 by Automationhc Typo mistake
Danp2 Posted May 18, 2015 Posted May 18, 2015 (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 May 18, 2015 by Danp2 Latest Webdriver UDF Release Webdriver Wiki FAQs
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now