JailDoctor Posted April 10, 2008 Share Posted April 10, 2008 I have to click a button on a window, so I used ControlClick command.The problem is that most of the button IDs change every time the window is opened.Spy shows me the following:Basic Window infoTitle: - Co-Signature 1 (The client's Name precedes the -)Class: WindowsForms10.window.8.app3Basic Control infoClass: WindowsForms10.BUTTON.app3Instance 4Control Tab ValuesClass: WindowsForms10.BUTTON.app3Instance: 4ID: 5573106 (This number changes every time the window appears)Text: OtherPosition: 355, 45Size: 56, 16ControlClick Coords: 2,7 (This numbers change every time the window appears)Style: 0x5601000BExStyle: 0x00000000Handle: 0x005509F2 (This number changes every time the window appears)I use this code and sometimes it works and other times it doesn't.CODEOpt("WinTitleMatchMode", 2)HotKeySet("^!t", "MyExit")While 1 If WinExists("- Co-Signature 1") Then WinActivate ("- Co-Signature 1") WinWait ("- Co-Signature 1") ControlGetFocus ("[CLASS:BUTTON,INSTANCE:4 ]") ControlClick (" - Co-Signature 1","Other","[CLASS:WindowsForms10.BUTTON.app3; INSTANCE:4]") Send("{TAB}The name of the cosigner goes here") ; TAB is because the next Edit box |WindowsForms10.EDIT.app31| has the same problem (changing most Control IDs). EndIfSleep (300)WEndFunc MyExit() ExitEndFunc ;==>MyExit Link to comment Share on other sites More sharing options...
MHz Posted April 11, 2008 Share Posted April 11, 2008 Yeah, Dotnet applications are like that. You can use the text of a control which can be OK for buttons hopefully. WinGetClassList() can be used to get all the classes of the controls and find the Edit control as it is hopefully unique within that window. Opt("WinTitleMatchMode", 2) HotKeySet("^!t", "MyExit") While 1 If WinExists("- Co-Signature 1") Then WinActivate("- Co-Signature 1") If WinWaitActive("- Co-Signature 1", "", 1) Then $ctrl = _CtrlGetClass('- Co-Signature 1', '', 'WindowsForms10.EDIT') If $ctrl Then ControlFocus('- Co-Signature 1', '', 'Other') ControlClick(" - Co-Signature 1", "Other", "Other") ControlSend("- Co-Signature 1", "", $ctrl, 'The name of the cosigner goes here') EndIf ;Send("{TAB}The name of the cosigner goes here") ; TAB is because the next Edit box |WindowsForms10.EDIT.app31| has the same problem (changing most Control IDs). EndIf EndIf Sleep(300) WEnd Func MyExit() Exit EndFunc ;==>MyExit Func _CtrlGetClass($sTitle, $sText, $sClassType) Local $split $sClasses = WinGetClassList($sTitle, $sText) If Not @error Then $split = StringSplit($sClasses, @LF) For $i = 1 To UBound($split) -1 If StringInStr($split[$i], $sClassType) Then Return $split[$i] EndIf Next EndIf Return '' EndFunc Link to comment Share on other sites More sharing options...
JailDoctor Posted April 15, 2008 Author Share Posted April 15, 2008 I can't get the text to be entered into the edit box. I run the script and the "other" radio button is clicked, like before. The edit box is enabled (from shaded to bright white color) but no text is entered with the ControlSend command. I have to physically click the edit box to manually enter the text. Link to comment Share on other sites More sharing options...
MHz Posted April 17, 2008 Share Posted April 17, 2008 You may need to try some code variations to make it work. I do not have the application to test so I can only offer basic support. Try in the order of ControlSetText(), ControlSend() and Send() to send to the edit control. Add a Msgbox() and compare with AutoIt Info Tool if the class name is correct. I tested _CtrlGetClass() before posting but perhaps it may not read well from your application. Perhaps the parameter of "WindowsForms10.EDIT" in _CtrlGetClass() is not found upon next start so perhaps just "EDIT" may do. Try this variation: expandcollapse popupOpt("WinTitleMatchMode", 2) HotKeySet("^!t", "MyExit") While 1 If WinExists("- Co-Signature 1") Then WinActivate("- Co-Signature 1") If WinWaitActive("- Co-Signature 1", "", 1) Then $ctrl = _CtrlGetClass('- Co-Signature 1', '', '.EDIT.') If $ctrl Then ControlFocus('- Co-Signature 1', '', 'Other') ControlClick(" - Co-Signature 1", "Other", "Other") ControlFocus('- Co-Signature 1', '', $ctrl) ControlSetText("- Co-Signature 1", "", $ctrl, 'The name of the cosigner goes here') MsgBox(0x40000, '$ctrl', $ctrl); debug EndIf ;Send("{TAB}The name of the cosigner goes here") ; TAB is because the next Edit box |WindowsForms10.EDIT.app31| has the same problem (changing most Control IDs). EndIf EndIf Sleep(300) WEnd Func MyExit() Exit EndFunc ;==>MyExit Func _CtrlGetClass($sTitle, $sText, $sClassType) Local $split $sClasses = WinGetClassList($sTitle, $sText) If Not @error Then $split = StringSplit($sClasses, @LF) For $i = 1 To UBound($split) -1 If StringInStr($split[$i], $sClassType) Then Return $split[$i] EndIf Next EndIf Return '' EndFunc 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