Jump to content

Recommended Posts

Using this thread: Using UI Automation Code in AutoIt

I came up with this code:

 

; --- Find window/control ---

ConsoleWrite( "--- Find window/control ---" & @CRLF )

While 1
Local $pCondition0
$oUIAutomation.CreatePropertyCondition( $UIA_ClassNamePropertyId, "Chrome_WidgetWin_1", $pCondition0 )
If Not $pCondition0 Then Return ConsoleWrite( "$pCondition0 ERR" & @CRLF )
ConsoleWrite( "$pCondition0 OK" & @CRLF )

Local $pPane1, $oPane1
$oDesktop.FindFirst( $TreeScope_Children, $pCondition0, $pPane1 )
$oPane1 = ObjCreateInterface( $pPane1, $sIID_IUIAutomationElement, $dtag_IUIAutomationElement )
If Not IsObj( $oPane1 ) Then Return ConsoleWrite( "$oPane1 ERR" & @CRLF )
ConsoleWrite( "$oPane1 OK" & @CRLF )

; --- Find window/control ---

ConsoleWrite( "--- Find window/control ---" & @CRLF )

Local $pCondition1, $pCondition2, $pAndCondition2
$oUIAutomation.CreatePropertyCondition( $UIA_ControlTypePropertyId, $UIA_MenuItemControlTypeId, $pCondition1 )
$oUIAutomation.CreatePropertyCondition( $UIA_NamePropertyId, "FireShot - Capture page
Are acces la acest site", $pCondition2 )
$oUIAutomation.CreateAndCondition( $pCondition1, $pCondition2, $pAndCondition2 )
If Not $pAndCondition2 Then Return ConsoleWrite( "$pAndCondition2 ERR" & @CRLF )
ConsoleWrite( "$pAndCondition2 OK" & @CRLF )

Local $pMenuItem1, $oMenuItem1
$oPane1.FindFirst( $TreeScope_Descendants, $pAndCondition2, $pMenuItem1 )
$oMenuItem1 = ObjCreateInterface( $pMenuItem1, $sIID_IUIAutomationElement, $dtag_IUIAutomationElement )
If Not IsObj( $oMenuItem1 ) Then Return ConsoleWrite( "$oMenuItem1 ERR" & @CRLF )
ConsoleWrite( "$oMenuItem1 OK" & @CRLF )

; --- Invoke Pattern (action) Object ---

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

Local $pInvokePattern1, $oInvokePattern1
$oMenuItem1.GetCurrentPattern( $UIA_InvokePatternId, $pInvokePattern1 )
$oInvokePattern1 = ObjCreateInterface( $pInvokePattern1, $sIID_IUIAutomationInvokePattern, $dtag_IUIAutomationInvokePattern )
If Not IsObj( $oInvokePattern1 ) Then Return ConsoleWrite( "$oInvokePattern1 ERR" & @CRLF )
ConsoleWrite( "$oInvokePattern1 OK" & @CRLF )

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

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

$oInvokePattern1.Invoke()
ConsoleWrite( "$oInvokePattern1.Invoke()" & @CRLF )


WEnd

; Code corrections:
; UIA_Constants.au3 path
; UIA_Functions.au3 path
; UIA_SafeArray.au3 path
; UIA_Variant.au3 path
; Code to open target appl
;   If it isn't already open
; Create undeclared variables
;   There should be very few
; Delete double declared variables
;   There should be very few
; Window, Pane, Parent and Control names
;   Most names should be correct
; Fill out Pattern (action) Method parameters
;   See Microsoft docu for the Pattern Method
; Place the code inside a function
;   Necessary due to Return statements

I don't understeand, what am i not reading?

The task is simple:

  - Instead of going to click on that extension with coord;


  - I want to tell AutoIT: Hey, do you see that extension? If yes, click on it.

But i don't understeand what i should do.

 

Link to post
Share on other sites

Hi. Try change this:

50 minutes ago, BogdanNicolescu said:

$oUIAutomation.CreatePropertyCondition( $UIA_NamePropertyId, "FireShot - Capture page Are acces la acest site", $pCondition2 )

For:

$oUIAutomation.CreatePropertyCondition( $UIA_NamePropertyId, "FireShot - Capture page" & @LF & "Are acces la acest site", $pCondition2 )

 

Link to post
Share on other sites

What represent this: "error: 'Return' not allowed from global scope."?

P.S. I still get errors, but i'm starting to "delete" them ... kinda, don't know if this type of "delete" is the solution. And by delete i mean i started to declare them globally.

Link to post
Share on other sites

Exactly what is written, that you are trying to return from a global scope. Read this to understand more about Function and Returnhttps://www.autoitscript.com/autoit3/docs/keywords/Func.htm

The example code should look like this:

#include "CUIAutomation2.au3"

Example()

Func Example()
    ; Create UI Automation object
    Local $oUIAutomation = ObjCreateInterface( $sCLSID_CUIAutomation, $sIID_IUIAutomation, $dtagIUIAutomation )
    If Not IsObj( $oUIAutomation ) Then Return ConsoleWrite( "$oUIAutomation ERR" & @CRLF )
    ConsoleWrite( "$oUIAutomation OK" & @CRLF )

    ; Get Desktop element
    Local $pDesktop, $oDesktop
    $oUIAutomation.GetRootElement( $pDesktop )
    $oDesktop = ObjCreateInterface( $pDesktop, $sIID_IUIAutomationElement, $dtagIUIAutomationElement )
    If Not IsObj( $oDesktop ) Then Return ConsoleWrite( "$oDesktop ERR" & @CRLF )
    ConsoleWrite( "$oDesktop OK" & @CRLF )
  
    ConsoleWrite( "--- Find window/control ---" & @CRLF )

    Local $pCondition0
    $oUIAutomation.CreatePropertyCondition( $UIA_ClassNamePropertyId, "Chrome_WidgetWin_1", $pCondition0 )
    If Not $pCondition0 Then Return ConsoleWrite( "$pCondition0 ERR" & @CRLF )
    ConsoleWrite( "$pCondition0 OK" & @CRLF )

    Local $pPane1, $oPane1
    $oDesktop.FindFirst( $TreeScope_Children, $pCondition0, $pPane1 )
    $oPane1 = ObjCreateInterface( $pPane1, $sIID_IUIAutomationElement, $dtagIUIAutomationElement )
    If Not IsObj( $oPane1 ) Then Exit ConsoleWrite( "$oPane1 ERR" & @CRLF )
    ConsoleWrite( "$oPane1 OK" & @CRLF )

    ; --- Find window/control ---

    ConsoleWrite( "--- Find window/control ---" & @CRLF )

    Local $pCondition1, $pCondition2, $pAndCondition2
    $oUIAutomation.CreatePropertyCondition( $UIA_ControlTypePropertyId, $UIA_MenuItemControlTypeId, $pCondition1 )
    $oUIAutomation.CreatePropertyCondition( $UIA_NamePropertyId, "FireShot - Capture page" & @LF & "Are acces la acest site", $pCondition2 )
    $oUIAutomation.CreateAndCondition( $pCondition1, $pCondition2, $pAndCondition2 )
    If Not $pAndCondition2 Then Return ConsoleWrite( "$pAndCondition2 ERR" & @CRLF )
    ConsoleWrite( "$pAndCondition2 OK" & @CRLF )

    Local $pMenuItem1, $oMenuItem1
    $oPane1.FindFirst( $TreeScope_Descendants, $pAndCondition2, $pMenuItem1 )
    $oMenuItem1 = ObjCreateInterface( $pMenuItem1, $sIID_IUIAutomationElement, $dtagIUIAutomationElement )
    If Not IsObj( $oMenuItem1 ) Then Return ConsoleWrite( "$oMenuItem1 ERR" & @CRLF )
    ConsoleWrite( "$oMenuItem1 OK" & @CRLF )

    ; --- Invoke Pattern (action) Object ---

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

    Local $pInvokePattern1, $oInvokePattern1
    $oMenuItem1.GetCurrentPattern( $UIA_InvokePatternId, $pInvokePattern1 )
    $oInvokePattern1 = ObjCreateInterface( $pInvokePattern1, $sIID_IUIAutomationInvokePattern, $dtagIUIAutomationInvokePattern )
    If Not IsObj( $oInvokePattern1 ) Then Return ConsoleWrite( "$oInvokePattern1 ERR" & @CRLF )
    ConsoleWrite( "$oInvokePattern1 OK" & @CRLF )

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

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

    $oInvokePattern1.Invoke()
    ConsoleWrite( "$oInvokePattern1.Invoke()" & @CRLF )
EndFunc

 

Link to post
Share on other sites
8 minutes ago, AlfredF said:

Exactly what is written, that you are trying to return from a global scope. Read this to understand more about Function and Returnhttps://www.autoitscript.com/autoit3/docs/keywords/Func.htm

The example code should look like this:

#include "CUIAutomation2.au3"

Example()

Func Example()
    ; Create UI Automation object
    Local $oUIAutomation = ObjCreateInterface( $sCLSID_CUIAutomation, $sIID_IUIAutomation, $dtagIUIAutomation )
    If Not IsObj( $oUIAutomation ) Then Return ConsoleWrite( "$oUIAutomation ERR" & @CRLF )
    ConsoleWrite( "$oUIAutomation OK" & @CRLF )

    ; Get Desktop element
    Local $pDesktop, $oDesktop
    $oUIAutomation.GetRootElement( $pDesktop )
    $oDesktop = ObjCreateInterface( $pDesktop, $sIID_IUIAutomationElement, $dtagIUIAutomationElement )
    If Not IsObj( $oDesktop ) Then Return ConsoleWrite( "$oDesktop ERR" & @CRLF )
    ConsoleWrite( "$oDesktop OK" & @CRLF )
  
    ConsoleWrite( "--- Find window/control ---" & @CRLF )

    Local $pCondition0
    $oUIAutomation.CreatePropertyCondition( $UIA_ClassNamePropertyId, "Chrome_WidgetWin_1", $pCondition0 )
    If Not $pCondition0 Then Return ConsoleWrite( "$pCondition0 ERR" & @CRLF )
    ConsoleWrite( "$pCondition0 OK" & @CRLF )

    Local $pPane1, $oPane1
    $oDesktop.FindFirst( $TreeScope_Children, $pCondition0, $pPane1 )
    $oPane1 = ObjCreateInterface( $pPane1, $sIID_IUIAutomationElement, $dtagIUIAutomationElement )
    If Not IsObj( $oPane1 ) Then Exit ConsoleWrite( "$oPane1 ERR" & @CRLF )
    ConsoleWrite( "$oPane1 OK" & @CRLF )

    ; --- Find window/control ---

    ConsoleWrite( "--- Find window/control ---" & @CRLF )

    Local $pCondition1, $pCondition2, $pAndCondition2
    $oUIAutomation.CreatePropertyCondition( $UIA_ControlTypePropertyId, $UIA_MenuItemControlTypeId, $pCondition1 )
    $oUIAutomation.CreatePropertyCondition( $UIA_NamePropertyId, "FireShot - Capture page" & @LF & "Are acces la acest site", $pCondition2 )
    $oUIAutomation.CreateAndCondition( $pCondition1, $pCondition2, $pAndCondition2 )
    If Not $pAndCondition2 Then Return ConsoleWrite( "$pAndCondition2 ERR" & @CRLF )
    ConsoleWrite( "$pAndCondition2 OK" & @CRLF )

    Local $pMenuItem1, $oMenuItem1
    $oPane1.FindFirst( $TreeScope_Descendants, $pAndCondition2, $pMenuItem1 )
    $oMenuItem1 = ObjCreateInterface( $pMenuItem1, $sIID_IUIAutomationElement, $dtagIUIAutomationElement )
    If Not IsObj( $oMenuItem1 ) Then Return ConsoleWrite( "$oMenuItem1 ERR" & @CRLF )
    ConsoleWrite( "$oMenuItem1 OK" & @CRLF )

    ; --- Invoke Pattern (action) Object ---

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

    Local $pInvokePattern1, $oInvokePattern1
    $oMenuItem1.GetCurrentPattern( $UIA_InvokePatternId, $pInvokePattern1 )
    $oInvokePattern1 = ObjCreateInterface( $pInvokePattern1, $sIID_IUIAutomationInvokePattern, $dtagIUIAutomationInvokePattern )
    If Not IsObj( $oInvokePattern1 ) Then Return ConsoleWrite( "$oInvokePattern1 ERR" & @CRLF )
    ConsoleWrite( "$oInvokePattern1 OK" & @CRLF )

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

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

    $oInvokePattern1.Invoke()
    ConsoleWrite( "$oInvokePattern1.Invoke()" & @CRLF )
EndFunc

 

What i was missing was this: #include "CUIAutomation2.au3"

But now if i want to integrate it into another script, how can i do it? I get all sort of errors ...

Link to post
Share on other sites

Glad you got something working. It shouldn't be difficult to integrate the example of how to click the extension into your script. Remembering that if you intend to manipulate the website in Chrome, you should be aware that depending on your Windows version, Chrome window needs to have focus (W10 for example) before you try to access the content of the document (ie. website). If you need more help, you should post the errors and a small reproducer, to make it easy to understand what is not working and help you.

Link to post
Share on other sites
12 hours ago, AlfredF said:

Glad you got something working. It shouldn't be difficult to integrate the example of how to click the extension into your script. Remembering that if you intend to manipulate the website in Chrome, you should be aware that depending on your Windows version, Chrome window needs to have focus (W10 for example) before you try to access the content of the document (ie. website). If you need more help, you should post the errors and a small reproducer, to make it easy to understand what is not working and help you.

It's nothing too complicated stuff (the task i mean) that i want to put this code to work, but the code it's self, is bending my brian :)) That's the complicated stuff. I think of it being hard now, but when i will get the hang of it and understand the logic behind all lines, will be a breeze :D

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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...