Sign in to follow this  
Followers 0
JailDoctor

ControlClick Problem

4 posts in this topic

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 info

Title: - Co-Signature 1 (The client's Name precedes the -)

Class: WindowsForms10.window.8.app3

Basic Control info

Class: WindowsForms10.BUTTON.app3

Instance 4

Control Tab Values

Class: WindowsForms10.BUTTON.app3

Instance: 4

ID: 5573106 (This number changes every time the window appears)

Text: Other

Position: 355, 45

Size: 56, 16

ControlClick Coords: 2,7 (This numbers change every time the window appears)

Style: 0x5601000B

ExStyle: 0x00000000

Handle: 0x005509F2 (This number changes every time the window appears)

I use this code and sometimes it works and other times it doesn't.

CODE
Opt("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).

EndIf

Sleep (300)

WEnd

Func MyExit()

Exit

EndFunc ;==>MyExit

Share this post


Link to post
Share on other sites



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

:D

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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:

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', '', '.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

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
Sign in to follow this  
Followers 0