Jump to content

Recommended Posts

Posted

Hello,

I tried to make a program for logging to Adobe InDesign. I am able to identify controls, but when I click on a button "Continue" after the email is entered by the script using SetValue()  an error is thrown that a valid email address is needed. I also run PropertyChangedEventHandlerEx.au3 that I found at UI Automation Events. I modifieded it to display only relevant data. Info that I get from that script shows that property has been changed.

Script will be running on Windows server. If I use WinActivate() and Send() then script works,  but then issues arise when machine is locked.

#include-once
#include <WinAPIProc.au3>
#include <Array.au3>
;~ #include "Includes\UIA_Constants.au3" ; Can be copied from UIASpy Includes folder
#include "UIA_Functions.au3" ; Can be copied from UIASpy Includes folder
;#include "UIA_SafeArray.au3" ; Can be copied from UIASpy Includes folder
;#include "UIA_Variant.au3" ; Can be copied from UIASpy Includes folder
Opt("TrayIconHide", 1)
Opt("MustDeclareVars", 1)

Global $sIdentificationTitle = "Adobe InDesign 2020"
Global $sEmail = "validEmail"
_Main()

Func _Main()


    Local $oUIAutomation = ObjCreateInterface($sCLSID_CUIAutomation, $sIID_IUIAutomation, $dtag_IUIAutomation)
    If Not IsObj($oUIAutomation) Then Return _ConsoleWrite("$oUIAutomation ERR")
    _ConsoleWrite("$oUIAutomation OK")



    Local $oInDesingWindow = __FindinDesignWindow()

    ; --- Find email input field ---

    _ConsoleWrite("--- Find email input field  ---")

    Local $pCondition0, $pCondition1, $pAndCondition3
    $oUIAutomation.CreatePropertyCondition($UIA_AutomationIdPropertyId, "EmailPage-EmailField", $pCondition0)
    If Not $pCondition0 Then Return _ConsoleWrite("$pCondition0 ERR")
    _ConsoleWrite("$pCondition0 OK")
    $oUIAutomation.CreatePropertyCondition($UIA_ControlTypePropertyId, $UIA_EditControlTypeId, $pCondition1)
    If Not $pCondition1 Then Return _ConsoleWrite("$pCondition1 ERR")
    _ConsoleWrite("$pCondition1 OK")
    $oUIAutomation.CreateAndCondition($pCondition0, $pCondition1, $pAndCondition3)
    If Not $pAndCondition3 Then Return ConsoleWrite("$pAndCondition3 ERR" & @CRLF)
    ConsoleWrite("$pAndCondition3 OK" & @CRLF)

    Local $pEdit1, $oEmail
    Do
        $oInDesingWindow.FindFirst($TreeScope_Descendants, $pAndCondition3, $pEdit1)
        $oEmail = ObjCreateInterface($pEdit1, $sIID_IUIAutomationElement, $dtag_IUIAutomationElement)
    Until IsObj($oEmail)
    _ConsoleWrite("$oEmail OK")

    ; --- Value Pattern (action) Object ---

    ConsoleWrite("--- Value Pattern (action) Object ---" & @CRLF)

    Local $pValuePattern1, $oValuePattern1
    $oEmail.GetCurrentPattern($UIA_ValuePatternId, $pValuePattern1)
    $oValuePattern1 = ObjCreateInterface($pValuePattern1, $sIID_IUIAutomationValuePattern, $dtag_IUIAutomationValuePattern)
    If Not IsObj($oValuePattern1) Then Return ConsoleWrite("$oValuePattern1 ERR" & @CRLF)
    ConsoleWrite("$oValuePattern1 OK" & @CRLF)

    ; --- Value Pattern (action) Methods ---

    ConsoleWrite("--- Value Pattern (action) Methods ---" & @CRLF)

    $oValuePattern1.SetValue($sEmail)
    ConsoleWrite("$oValuePattern1.SetValue()" & @CRLF)
    Local $sValueRead
    $oValuePattern1.CurrentValue($sValueRead)
    _ConsoleWrite("TestCondition:" & $sValueRead == $sEmail)

Return
    ; --- Find Continue button ---

    _ConsoleWrite("--- Find Continue button ---")

    Local $pCondition0
    $oUIAutomation.CreatePropertyCondition($UIA_NamePropertyId, "Continue", $pCondition0)
    If Not $pCondition0 Then Return _ConsoleWrite("$pCondition0 ERR")
    _ConsoleWrite("$pCondition0 OK")

    Local $pButton1, $oContinue
    $oInDesingWindow.FindFirst($TreeScope_Descendants, $pCondition0, $pButton1)
    $oContinue = ObjCreateInterface($pButton1, $sIID_IUIAutomationElement, $dtag_IUIAutomationElement)
    If Not IsObj($oContinue) Then Return _ConsoleWrite("$oContinue ERR")
    _ConsoleWrite("$oContinue OK")

    ; --- Click on continue button ---

    _ConsoleWrite("--- Click on continue button ---")

    Local $pInvokePattern1, $oClickContinue
    $oContinue.GetCurrentPattern($UIA_InvokePatternId, $pInvokePattern1)
    $oClickContinue = ObjCreateInterface($pInvokePattern1, $sIID_IUIAutomationInvokePattern, $dtag_IUIAutomationInvokePattern)
    If Not IsObj($oClickContinue) Then Return _ConsoleWrite("$oClickContinue ERR")
    _ConsoleWrite("$oClickContinue OK")

    ; --- Invoke Pattern (action) Methods ---

    _ConsoleWrite("--- Invoke Pattern  - Continue Button ---")
    $oClickContinue .Invoke()
    _ConsoleWrite("$oInvokePattern1.Invoke()")

EndFunc   ;==>_Main

Func _ConsoleWrite($sData)
    Return ConsoleWrite($sData & @CRLF)
EndFunc   ;==>_ConsoleWrite

Func __FindinDesignWindow()

    ; Create UI Automation object
    Local $oUIAutomation = ObjCreateInterface($sCLSID_CUIAutomation, $sIID_IUIAutomation, $dtag_IUIAutomation)
    If Not IsObj($oUIAutomation) Then Return _ConsoleWrite("$oUIAutomation ERR")
    _ConsoleWrite("$oUIAutomation OK")

    ; Get Desktop element
    Local $pDesktop, $oDesktop
    $oUIAutomation.GetRootElement($pDesktop)
    $oDesktop = ObjCreateInterface($pDesktop, $sIID_IUIAutomationElement, $dtag_IUIAutomationElement)
    If Not IsObj($oDesktop) Then Return _ConsoleWrite("$oDesktop ERR")
    _ConsoleWrite("$oDesktop OK")
    ; --- Find inDesing window ---

    _ConsoleWrite("--- Find inDesing window ---")

    Local $pCondition0
    $oUIAutomation.CreatePropertyCondition($UIA_NamePropertyId, $sIdentificationTitle, $pCondition0)
    If Not $pCondition0 Then Return _ConsoleWrite("$pCondition0 ERR")
    _ConsoleWrite("$pCondition0 OK")

    Local $pWindow1, $oInDesing
    $oDesktop.FindFirst($TreeScope_Children, $pCondition0, $pWindow1)
    $oInDesing = ObjCreateInterface($pWindow1, $sIID_IUIAutomationElement, $dtag_IUIAutomationElement)
    If Not IsObj($oInDesing) Then Return _ConsoleWrite("$oInDesing ERR")
    _ConsoleWrite("$oInDesing OK")

    Return $oInDesing



EndFunc   ;==>__FindinDesignWindow

Here is output from SciTE

>"C:\Program Files (x86)\AutoIt3\SciTE\..\AutoIt3.exe" "C:\Program Files (x86)\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.au3" /run /prod /ErrorStdOut /in "C:\Users\Administrator\Desktop\UIASpy\tesInDesign.au3" /UserParams    
+>18:54:36 Starting AutoIt3Wrapper (19.1127.1402.0} from:SciTE.exe (4.2.0.0)  Keyboard:0000041A  OS:WIN_2016/  CPU:X64 OS:X64  Environment(Language:0409)  CodePage:0  utf8.auto.check:4
+>         SciTEDir => C:\Program Files (x86)\AutoIt3\SciTE   UserDir => C:\Users\Administrator\AppData\Local\AutoIt v3\SciTE\AutoIt3Wrapper   SCITE_USERHOME => C:\Users\Administrator\AppData\Local\AutoIt v3\SciTE 
>Running AU3Check (3.3.14.5)  from:C:\Program Files (x86)\AutoIt3  input:C:\Users\Administrator\Desktop\UIASpy\tesInDesign.au3
+>18:54:36 AU3Check ended.rc:0
>Running:(3.3.14.5):C:\Program Files (x86)\AutoIt3\autoit3.exe "C:\Users\Administrator\Desktop\UIASpy\tesInDesign.au3"    
+>Setting Hotkeys...--> Press Ctrl+Alt+Break to Restart or Ctrl+BREAK to Stop.
$oUIAutomation OK
$oUIAutomation OK
$oDesktop OK
--- Find inDesing window ---
$pCondition0 OK
$oInDesing OK
--- Find email input field  ---
$pCondition0 OK
$pCondition1 OK
$pAndCondition3 OK
$oEmail OK
--- Value Pattern (action) Object ---
$oValuePattern1 OK
--- Value Pattern (action) Methods ---
$oValuePattern1.SetValue()
False
--- Find Continue button ---
$pCondition0 OK
$oContinue OK
--- Click on continue button ---
$oClickContinue OK
--- Invoke Pattern  - Continue Button ---
$oInvokePattern1.Invoke()
+>18:54:37 AutoIt3.exe ended.rc:0
+>18:54:37 AutoIt3Wrapper Finished.
>Exit code: 0    Time: 1.455

Here is modifieded PropertyChangedEventHandlerEx.au3 and console output.

#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7

;#AutoIt3Wrapper_UseX64=y

Opt( "MustDeclareVars", 1 )

; Windows Task Manager and other programs
;#RequireAdmin ; Windows 10, Run SciTE as administrator

#include "..\Includes\UIAEH_PropertyChangedEventHandler.au3"

Example()

Func Example()
    UIAEH_PropertyChangedEventHandlerCreate()
    If Not IsObj( $oUIAEH_PropertyChangedEventHandler ) Then Return ConsoleWrite( "$oUIAEH_PropertyChangedEventHandler ERR" & @CRLF )
    ConsoleWrite( "$oUIAEH_PropertyChangedEventHandler OK" & @CRLF )

    Local $oUIAutomation = ObjCreateInterface( $sCLSID_CUIAutomation,  $sIID_IUIAutomation,  $dtag_IUIAutomation  ) ; Windows 7
    ;Local $oUIAutomation = ObjCreateInterface( $sCLSID_CUIAutomation8, $sIID_IUIAutomation2, $dtag_IUIAutomation2 ) ; Windows 8
    ;Local $oUIAutomation = ObjCreateInterface( $sCLSID_CUIAutomation8, $sIID_IUIAutomation3, $dtag_IUIAutomation3 ) ; Windows 8.1
    ;Local $oUIAutomation = ObjCreateInterface( $sCLSID_CUIAutomation8, $sIID_IUIAutomation3, $dtag_IUIAutomation3 ) ; Windows 10 First
    ;Local $oUIAutomation = ObjCreateInterface( $sCLSID_CUIAutomation8, $sIID_IUIAutomation6, $dtag_IUIAutomation6 ) ; Windows 10 Last
    If Not IsObj( $oUIAutomation ) Then Return ConsoleWrite( "$oUIAutomation ERR" & @CRLF )
    ConsoleWrite( "$oUIAutomation OK" & @CRLF )

    Local $pDesktop
    $oUIAutomation.GetRootElement( $pDesktop )
    If Not $pDesktop Then Return ConsoleWrite( "$pDesktop ERR" & @CRLF )
    ConsoleWrite( "$pDesktop OK" & @CRLF )

    Local $tPropertyArray = DllStructCreate( "int[2]" )
    DllStructSetData( $tPropertyArray, 1, $UIA_NamePropertyId, 1 )
    DllStructSetData( $tPropertyArray, 1, $UIA_ValueValuePropertyId, 2 )
    Local $iError = $oUIAutomation.AddPropertyChangedEventHandlerNativeArray( $pDesktop, $TreeScope_Subtree, 0, $oUIAEH_PropertyChangedEventHandler, $tPropertyArray, 2 )
    If $iError Then Return ConsoleWrite( "AddPropertyChangedEventHandlerNativeArrayr() ERR" & @CRLF )
    ConsoleWrite( "AddPropertyChangedEventHandlerNativeArray() OK" & @CRLF )

    HotKeySet( "{ESC}", "Quit" )

    While Sleep(10)
    WEnd
EndFunc

Func Quit()
    UIAEH_PropertyChangedEventHandlerDelete()
    Exit
EndFunc

; This is the function that receives events
Func UIAEH_PropertyChangedEventHandler_HandlePropertyChangedEvent( $pSelf, $pSender, $iPropertyId, $vNewValue ) ; Ret: long  Par: ptr;int;variant
    Local $oSender = ObjCreateInterface( $pSender, $sIID_IUIAutomationElement,  $dtag_IUIAutomationElement  ) ; Windows 7
    ;Local $oSender = ObjCreateInterface( $pSender, $sIID_IUIAutomationElement2, $dtag_IUIAutomationElement2 ) ; Windows 8
    ;Local $oSender = ObjCreateInterface( $pSender, $sIID_IUIAutomationElement3, $dtag_IUIAutomationElement3 ) ; Windows 8.1
    ;Local $oSender = ObjCreateInterface( $pSender, $sIID_IUIAutomationElement4, $dtag_IUIAutomationElement4 ) ; Windows 10 First
    ;Local $oSender = ObjCreateInterface( $pSender, $sIID_IUIAutomationElement9, $dtag_IUIAutomationElement9 ) ; Windows 10 Last
    $oSender.AddRef()
    If UIAEH_GetCurrentPropertyValue( $oSender, $UIA_LocalizedControlTypePropertyId )="Modifica" Then
    ConsoleWrite( @CRLF & "UIAEH_PropertyChangedEventHandler_HandlePropertyChangedEvent: $iPropertyId = " & $iPropertyId & ", $vNewValue = " & $vNewValue & @CRLF )
    ConsoleWrite( "Title     = " & UIAEH_GetCurrentPropertyValue( $oSender, $UIA_NamePropertyId ) & @CRLF & _
                  "Class     = " & UIAEH_GetCurrentPropertyValue( $oSender, $UIA_ClassNamePropertyId ) & @CRLF & _
                  "Ctrl type = " & UIAEH_GetCurrentPropertyValue( $oSender, $UIA_ControlTypePropertyId ) & @CRLF & _
                  "Ctrl name = " & UIAEH_GetCurrentPropertyValue( $oSender, $UIA_LocalizedControlTypePropertyId ) & @CRLF & _
                  "Handle    = " & "0x" & Hex( UIAEH_GetCurrentPropertyValue( $oSender, $UIA_NativeWindowHandlePropertyId ) ) & @CRLF & _
                  "Value     = " & UIAEH_GetCurrentPropertyValue( $oSender, $UIA_ValueValuePropertyId ) & @CRLF  )
    EndIf
    Return 0x00000000 ; $S_OK
    #forceref $pSelf
EndFunc

; Auxiliary function (for simple properties only)
; There must be only one instance of this function
Func UIAEH_GetCurrentPropertyValue( $oSender, $iPropertyId )
    Local $vPropertyValue
    $oSender.GetCurrentPropertyValue( $iPropertyId, $vPropertyValue )
    Return $vPropertyValue
EndFunc

 

>"C:\Program Files (x86)\AutoIt3\SciTE\..\AutoIt3.exe" "C:\Program Files (x86)\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.au3" /run /prod /ErrorStdOut /in "C:\Users\Administrator\Desktop\UIAEHEvents\Examples\PropertyChangedEventHandlerEx.au3" /UserParams    
+>19:04:23 Starting AutoIt3Wrapper (19.1127.1402.0} from:SciTE.exe (4.2.0.0)  Keyboard:0000041A  OS:WIN_2016/  CPU:X64 OS:X64  Environment(Language:0409)  CodePage:0  utf8.auto.check:4
+>         SciTEDir => C:\Program Files (x86)\AutoIt3\SciTE   UserDir => C:\Users\Administrator\AppData\Local\AutoIt v3\SciTE\AutoIt3Wrapper   SCITE_USERHOME => C:\Users\Administrator\AppData\Local\AutoIt v3\SciTE 
>Running AU3Check (3.3.14.5)  params:-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7  from:C:\Program Files (x86)\AutoIt3  input:C:\Users\Administrator\Desktop\UIAEHEvents\Examples\PropertyChangedEventHandlerEx.au3
+>19:04:24 AU3Check ended.rc:0
>Running:(3.3.14.5):C:\Program Files (x86)\AutoIt3\autoit3.exe "C:\Users\Administrator\Desktop\UIAEHEvents\Examples\PropertyChangedEventHandlerEx.au3"    
+>Setting Hotkeys...--> Press Ctrl+Alt+Break to Restart or Ctrl+BREAK to Stop.
$oUIAEH_PropertyChangedEventHandler OK
$oUIAutomation OK
$pDesktop OK
AddPropertyChangedEventHandlerNativeArray() OK

UIAEH_PropertyChangedEventHandler_HandlePropertyChangedEvent: $iPropertyId = 30045, $vNewValue = 0x00000000
Title     = 
Class     = 
Ctrl type = 50004
Ctrl name = Modifica
Handle    = 0x00000000
Value     = validEmail

UIAEH_PropertyChangedEventHandler_HandlePropertyChangedEvent: $iPropertyId = 30045, $vNewValue = 0x00000000
Title     = Please enter an email address.
Class     = 
Ctrl type = 50004
Ctrl name = Modifica
Handle    = 0x00000000
Value     = 

>Process failed to respond; forcing abrupt termination...
>Exit code: 1    Time: 34.9

Main problem I have is with "Continue" button. I do not know where to go next.

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
×
×
  • Create New...