MikiiTakagi Posted January 6, 2020 Share Posted January 6, 2020 Im working on a program to enter automatically a lot of config from a excel file. From there everything work i was just wandering if there any way to verify if a click as worked fine? Sometime my ControlClick dont work. First i put some Sleep(100) after every click then I worked with WinWait and the name of the window. Is there any other way or a best practice to this? Since a change from sleep to WinWait, my program stop when a click is not register and i need to click manually to make it go again (Instead of continue clicking without the right window open). If you need any more information to answer simply ask! Im kinda new to programming and autoit. Thank you! PS: Sry for my bad language, English is a second language Link to comment Share on other sites More sharing options...
junkew Posted January 6, 2020 Share Posted January 6, 2020 Hard to answer. What type of application are you trying to enter your config in. Au3inf info will help or check some things in faq 31. After a click you have to check that things changef which can be - check if controls dissapeared - check if color changed in certain regions - ... FAQ 31 How to click some elements, FAQ 40 Test automation with AutoIt, Multithreading CLR .NET Powershell CMDLets Link to comment Share on other sites More sharing options...
TheXman Posted January 6, 2020 Share Posted January 6, 2020 (edited) How is anyone supposed to be able to tell you what the problem(s) with your script may be without seeing your script or at least the relevant parts? Any suggestions would be pure speculation without seeing any code. For instance, I could speculate that you probably aren't doing much, if any, checking of return codes after your functions. But as I said, that would be pure speculation. Edited January 6, 2020 by TheXman CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman Link to comment Share on other sites More sharing options...
MikiiTakagi Posted January 6, 2020 Author Share Posted January 6, 2020 Since I cannot post the "official" code im working on a exemple I can send you! Link to comment Share on other sites More sharing options...
MikiiTakagi Posted January 6, 2020 Author Share Posted January 6, 2020 (edited) expandcollapse popupFunc AddItem() For $rowIndex = 1 To UBound($ImportedItem,1)-1 $hwnd = WinActivate("Window 1") ControlClick("","", "[CLASS:Button; INSTANCE:5]") ; Click Add (Open new Window) WinWait("Window 2") ControlSetText("","","[CLASS:Edit; INSTANCE:1]", $ImportedItem[$rowIndex][1]) ; Add Description If $ImportedItem[$rowIndex][2] <> "" Then ControlSetText("","","[CLASS:Edit; INSTANCE:2]", $ImportedItem[$rowIndex][2]) ; Add Description 2 EndIf ControlClick("","", "[CLASS:SysTreeView32; INSTANCE:1]") ; Switch into SysTreeView Send("F") WinWait("Window 2", "Product::Fonction") ControlSend("", "", "[CLASS:ComboBox; INSTANCE:1]", $ImportedItem[$rowIndex][3]) ; Set Info 1 ControlSend("", "", "[CLASS:ComboBox; INSTANCE:2]", $ImportedItem[$rowIndex][4]) ; Set Info 2 ControlSend("", "", "[CLASS:ComboBox; INSTANCE:4]", $ImportedItem[$rowIndex][5]) ; Set Info 3 ControlClick("", "", "[CLASS:SysTreeView32; INSTANCE:1]") Send("C") Send("C") WinWait("Window 2", "Configuration") ControlClick("", "", "[CLASS:Button; INSTANCE:1]") ; Open new Window WinWait("Window 3") ControlClick("", "", "[CLASS:Button; INSTANCE:2]") ; Close Window 3 and open Window 4 WinWait("Window 4") ControlSetText("","","[CLASS:Edit; INSTANCE:1]", $ImportedItem[$rowIndex][6]) ; Set Info ControlClick("", "", "[CLASS:SysTreeView32; INSTANCE:1]") ; Change SysTreeView Send("I") For $NPrinter = 1 to 9 ; Set Multiple info inside the same place If $ImportedItem[$rowIndex][$NPrinter + 6] <> "" Then ControlSend("", "", "[ClASS:ComboBox; INSTANCE:$NPrinter]", $ImportedItem[$rowIndex][$NPrinter + 6]) EndIf Next ControlClick("", "", "[CLASS:SysTreeView32; INSTANCE:1]") ; Change SysTreeView Send("R") WinWait("Window 4", "Section 3") ControlClick("", "", "[CLASS:Button; INSTANCE:6]") ; Set info if needed If $ImportedItem[$rowIndex][16] <> "" Then ControlSend("", "", "[CLASS:ComboBox; INSTANCE:3]", $ImportedItem[$rowIndex][16]) EndIf ControlClick("", "", "[CLASS:Button; INSTANCE:54]") ; Close Window 3 ModeItem() ; ControlClick("", "", "[CLASS:Button; INSTANCE:39]") ; Close Window 2 Sleep(200) ChangeSecondaryProgress() Next EndFunc Func ModeItem() ControlClick("","", "[CLASS:Button; INSTANCE:4]") ; Click Copy WinWait("ModeItemWindow") ControlClick("","", "[CLASS:Button; INSTANCE:1]") ; Check Box 1 ControlClick("","", "[CLASS:Button; INSTANCE:2]") ; Check Box 2 ControlClick("","", "[CLASS:Button; INSTANCE:3]") ; Check Box 3 ControlClick("","", "[CLASS:Button; INSTANCE:4]") ; Click ok to close WinWaitClose("ModeItemWindow") EndFunc I was able to change some value to send you part of my code. There a lot of window opening and closing and sometime the "OK" button get highlight but not pressed. The code stop and wait for me to manually press it. It happen 2-3 time every 50 entry. That part is about 1/8 of the manipulation and the problem appear everywhere but not always.@TheXman You seems to talk about return in function what do you mean? Like i said im kinda new to programming :S Edited January 6, 2020 by MikiiTakagi Link to comment Share on other sites More sharing options...
TheXman Posted January 6, 2020 Share Posted January 6, 2020 (edited) 26 minutes ago, MikiiTakagi said: You seems to talk about return in function what do you mean? Like i said im kinda new to programming :S If you look in the help file for any given function, most will show what the return value is if the function was successful and it will show the value returned if it was unsuccessful. In addition, if the function sets @error, it will show you what @error is set to if the function fails. So if you want to know if a function is successful or not, the first thing you should do is check its return value or @error. For instance, ControlClick returns a 1 if successful and 0 if unsuccessful. ControlClick doesn't set @error so you don't need to take it into consideration. So to code defensively, you could use something like one of the following examples: If Not ControlClick(...) Then ;Do some error processing EndIf or If ControlClick(...) = 0 Then ;Do some error processing EndIf or Local $iReturnValue $iReturnValue = ControlClick(...) If $iReturnValue = 0 Then ;Do some error processing EndIf A lot of the examples that are given to users in the forum do not contain error checking. It's probably for several reason. One is probably just for brevity. Two, it's implied that the person requesting help will provide the error checking. Three, the "helper" has no idea what type of error processing needs to take place. So that is why you don't see much error checking in forum responses. However, if you look inside any UDFs, you will most likely see extensive error checking. Edited January 6, 2020 by TheXman CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman Link to comment Share on other sites More sharing options...
MikiiTakagi Posted January 6, 2020 Author Share Posted January 6, 2020 (edited) Do I need to write the ControlClick before the if to click then verify or the if will manage the Click if all the info is put into the "()"? The edit you just did answered my question! I get what you mean and gonna try it tomorrow thank for the info! Very appreciate the help! I got about 200 clicks to do is there any way to make it easier or i need to make it for every click? Just wanna learn something more ! Edited January 6, 2020 by MikiiTakagi Link to comment Share on other sites More sharing options...
TheXman Posted January 6, 2020 Share Posted January 6, 2020 (edited) 7 minutes ago, MikiiTakagi said: Do I need to write the ControlClick before the if to click then verify or the if will manage the Click if all the info is put into the "()"? It is up to you. As long as the function is syntactically correct, it can be within the If statement as a shown above or below. All of the following examples will work exactly the same. Which way you choose to do it is just a matter of style. If Not ControlSend("", "", "[CLASS:ComboBox; INSTANCE:1]", $ImportedItem[$rowIndex][3]) Then ;Do some error processing EndIf OR Local $iReturnValue $iReturnValue = ControlSend("", "", "[CLASS:ComboBox; INSTANCE:1]", $ImportedItem[$rowIndex][3]) If $iReturnValue = 0 Then ;Do some error processing EndIf OR Local $iReturnValue $iReturnValue = ControlSend("", "", "[CLASS:ComboBox; INSTANCE:1]", $ImportedItem[$rowIndex][3]) If Not $iReturnValue Then ;Do some error processing EndIf Edited January 6, 2020 by TheXman CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman Link to comment Share on other sites More sharing options...
TheXman Posted January 6, 2020 Share Posted January 6, 2020 (edited) 21 hours ago, MikiiTakagi said: I got about 200 clicks to do is there any way to make it easier or i need to make it for every click? Just wanna learn something more ! If the error processing for a failed ControlClick will always be the same, then you could wrap all of your ControlClick functionality into a user-defined function. Let's say that you wanted to exit the script with an error message if any ControlClick failed, then you could do something like: myControlClick("Title1", "Some text", "some control if info") myControlClick("Title1", "Some text", "some control if info") myControlClick("Title1", "Some text", "some control if info") myControlClick("Title1", "Some text", "some control if info") Func myControlClick($title, $text, $ctlid) If Not ControlClick($title, $text, $ctlid) Then ConsoleWrite("ControlClick error occurred." & @CRLF) Exit EndIf EndFunc I just typed that out as an example and did not check it for errors. But it shows what I mean by wrapping the functionality into a function. Ultimately, you can do it any way that works for you. That's what make coding so much fun! Edited January 7, 2020 by TheXman CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman Link to comment Share on other sites More sharing options...
MikiiTakagi Posted January 7, 2020 Author Share Posted January 7, 2020 That was exactly what I was thinking to do! I dont have time to work on this today but im gonna give you news a soon as I test it! Thanks! Link to comment Share on other sites More sharing options...
junkew Posted January 7, 2020 Share Posted January 7, 2020 (edited) Create a function sync Initially just add a sleep 2000 and add frequently at Manu places after each action the call to sync. First get it to work slowly and later enhance your sync function with checking objects for existence or mousecursor in a certain state to make the sleep obsolete. In general you are on a learning path where its probably smart to make many small functions in pairs like. Function actionOne Function validateOne Function actionTwo Function validateTwo And the in main of script you just write actionOne, validateOne and so on And then you will see later how many action and validation functions can be made more generic. Its probably to early for you but read faq 31 and 40. Links in my signature. They will direct you to more but complex things. Edited January 8, 2020 by junkew FAQ 31 How to click some elements, FAQ 40 Test automation with AutoIt, Multithreading CLR .NET Powershell CMDLets Link to comment Share on other sites More sharing options...
markyrocks Posted January 8, 2020 Share Posted January 8, 2020 The only other thing I can add to this is using loops to weed out sleeps. Something like $click="" $count="" While $click<>1 $click=Controlclick(args) $count+=1 Sleep(100) If $count=5 then Msgbox('','',"error") Endif Wend Spoiler "I Believe array math to be potentially fatal, I may be dying from array math poisoning" Link to comment Share on other sites More sharing options...
MikiiTakagi Posted January 8, 2020 Author Share Posted January 8, 2020 So i Just test it. Im still happy about the respond. Make me think about a lot for error handling! The problem is still there... Here what i have done If Not ControlClick("","", "[CLASS:Button; INSTANCE:4]") then MsgBox("", "ERROR", "ERROR OCCURED") EndIf WinWaitClose("Window") The click is for the button "OK" that close the window. I Run into a loop of 50 and at the 18 it stop. The button is highlighted and no msgbox appear. First i tried with the ControlSetText since one of my colleague did have a problem on his machine that the inputbox was not receiving any info and skip it (Simply adding "Sleep(200)" before and after the ControlSetText Fixed it. I tried with all 3 of the exemple you sended me and no msgbox appear and the code stop. Since I put WinWaitClose the script just stay in pause. I saw that the ControlSetText just return if he find the control not if it was entered. I got some idea i wanna try soon too like looking into the inputbox to valid what inside is the same as the thing I send inside. Link to comment Share on other sites More sharing options...
markyrocks Posted January 8, 2020 Share Posted January 8, 2020 (edited) Maybe adjust the logic Try something like If controlclick(args) then Winwaitclose(win) Else Msgbox("","","error") Endif It also might be an issue with false positives on the return of control click bc the parameters are so generic. I would be as specific as possible. In those parameters. Edited January 8, 2020 by markyrocks Spoiler "I Believe array math to be potentially fatal, I may be dying from array math poisoning" Link to comment Share on other sites More sharing options...
MikiiTakagi Posted January 9, 2020 Author Share Posted January 9, 2020 Sadly I wont be able to work on this project any more... I got some new important project I need to work right now. I keep everything in note and I appreciate a lot of the help you gave me! Before error handling was not really a thing in my head. Now I think of error handling on everything I write. Thank you very much! If I have a bit of time to work again on this project im gonna try to keep update and im gonna surely use the tips you gave me in other code! Thank you again! Link to comment Share on other sites More sharing options...
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