Sign in to follow this  
Followers 0
akorpan

Problem with object definition.

2 posts in this topic

Hello everyone.

I created script to click trough application (version 6.0.1).

Script clicked all objects in the application successfully.

But after I have reinstalled application (installed version 6.0.2), my script cannot run.

Object description changed from "Class:WindowsForms10.COMBOBOX.app.0.23beec7" to "Class:WindowsForms10.COMBOBOX.app.0.f68d0b"

How can I avoid this?

How can I make my script runable on different versions?

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

With .net application 'f68d0b' this part of the class will change every time a new version of the application is created. The good news is that this value will be the same for all .net windows and controls in the application so you can put the value in a global variable and use it like this

Global $g_sAppId = "f68d0b"

 "Class:WindowsForms10.COMBOBOX.app.0." & $g_sAppId

Additionally if the is a .net control that is always in the same position you can get the class using coordinates and populate the appid variable whenyour script starts.

Example:

Local $sAppId = ''

    $sCurClassnn = _arc_CtrlGetClassNN_ByPos("My window title", $sAppId ,10, 10)
    If Not ($sAppId = '') Then
        $g_sAppId = $sAppId
    EndIf


Func _CtrlGetClassNN_ByPos($sCaption, ByRef $sNetAppID_Out, $iX = -999, $iY = -999, $sClass_In = '' )
    Local $sClassList = ''
    Local $hWin = 0
    Local $aCtrlPos = 0 
    Local $sReturn = ''
    Local $Classnn = ''
    Local $MinW = 9999
    Local $MinH = 9999
    Local $aMPos = 0
    Local $OptMCM = 0
    Local $sSplitClass[2]
    Local $nCount = 0
    Local $aApp = 0
    
    WinWait($sCaption, "")
    If Not WinActive($sCaption, "") Then WinActivate($sCaption, "")
    WinWaitActive($sCaption, "")

    $hWin = WinGetHandle($sCaption)
    
    If $sClass_In = '' Then
        $sClassList = WinGetClassList($hWin)
        $sSplitClass = StringSplit(StringTrimRight($sClassList, 1), @LF)
    Else
        $sSplitClass[1] = $sClass_In
        $sSplitClass[0] = 1
    EndIf
    
    If $iX = -999 Or $iY = -999 Then
        $OptMCM = Opt('MouseCoordMode', 2)
        $aMPos = MouseGetPos()
        Opt('MouseCoordMode', $OptMCM)
    EndIf
    
    For $iCount = 1 To $sSplitClass[0]
        $nCount = 0
        While 1
            $nCount += 1
            $Classnn = $sSplitClass[$iCount] & $nCount
            $aCtrlPos = ControlGetPos($hWin, '', $Classnn )
            If @error Then ExitLoop
            If $aMPos[0] >= $aCtrlPos[0] And $aMPos[0] <= ($aCtrlPos[0] + $aCtrlPos[2]) _
                And $aMPos[1] >= $aCtrlPos[1] And $aMPos[1] <= ($aCtrlPos[1] + $aCtrlPos[3]) Then
                ; Check if the control is coincident or inside a previously indentified control, assuming 
                ; that we want the smallest control that the mouse coords are within.
                If $sSplitClass[$iCount] <> '' And $aCtrlPos[2] <= $MinW And $aCtrlPos[3] <= $MinH Then
                    ; check that the control is not hidden underneath another control.
                    If ControlCommand ( $sCaption, "", $Classnn, "IsVisible") Then
                        ; set new smallest size identified
                        $MinW = $aCtrlPos[2] 
                        $MinH = $aCtrlPos[3] 
                        $aApp = StringRegExp($sSplitClass[$iCount], "(?:app\.)(.+$)", 3)
                        If IsArray($aApp) Then 
                            $sNetAppID_Out = $aApp[0]
                        Else
                            $sNetAppID_Out = ''
                        EndIf
                        $sReturn = $Classnn
                    EndIf
                EndIf
            EndIf
        WEnd
    Next
    Return $sReturn
EndFunc

Edit: Had parameters in wrong order

Edited by Bowmore

"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook

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