Jump to content

Recommended Posts

Posted (edited)

Hello,

I'm trying to set a value in a combo box on a Chrome web page.  I've checked that the Chrome://accessibility is on and have checked to see that it's working with one of @LarsJ's scripts.  I've been able to locate the combo box and expand it.  I have then tried to put the contents into an element array.  When I check to see if the array is created there is no error.  When I check the size of the array with   '$oUIElementArray1.Length($iLength1)' the length is zero.  I then tried to set the value in the combo box with .SetValue().  No luck.  Next I tried to get the combo box items with '$oSelectionPattern1.GetCurrentSelection($pElementArray*)'.  My assumption is that the combo box items are put in an array - $pElementArray* though I couldn't get this to work in another program.  I've included the script and output.  This is my first attempt working with a website so that is likely where the problem is.  I've used all of the code except '$oSelectionPattern1' successfully in another script.

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

#include "C:\Users\Rod\Documents\AutoIt\Include\UIA_Constants.au3" ; Can be copied from UIASpy Includes folder
#include "C:\Users\Rod\Documents\AutoIt\Include\CUIAutomation2WithDuplicatesRemoved.au3"
;~ #include "C:\Users\Rod\Documents\AutoIt\Jigsaw Open Journalytix\Jigsaw Open Journalytix 01.au3"

Opt("MustDeclareVars", 1)

Example()

Func Example()
    ; Create UI Automation object
    Local $oUIAutomation = ObjCreateInterface($sCLSID_CUIAutomation8, $sIID_IUIAutomation5, $dtag_IUIAutomation5)
    If Not IsObj($oUIAutomation) Then Return ConsoleWrite(':' & @ScriptLineNumber & ':' & " $oUIAutomation ERR" & @CRLF)
    ConsoleWrite(':' & @ScriptLineNumber & ':' & " $oUIAutomation OK" & @CRLF)

    ; Get Desktop element
    Local $pDesktop, $oDesktop
    $oUIAutomation.GetRootElement($pDesktop)
    $oDesktop = ObjCreateInterface($pDesktop, $sIID_IUIAutomationElement8, $dtag_IUIAutomationElement8)
    If Not IsObj($oDesktop) Then Return ConsoleWrite(':' & @ScriptLineNumber & ':' & " $oDesktop ERR" & @CRLF)
    ConsoleWrite(':' & @ScriptLineNumber & ':' & " $oDesktop OK" & @CRLF)

    ; --- Find window/control ---

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

    ; locate browser
    Local $pCondition0
    $oUIAutomation.CreatePropertyCondition($UIA_ClassNamePropertyId, "Chrome_WidgetWin_1", $pCondition0)
    If Not $pCondition0 Then Return ConsoleWrite(':' & @ScriptLineNumber & ':' & " $pCondition0 ERR" & @CRLF)
    ConsoleWrite(':' & @ScriptLineNumber & ':' & " $pCondition0 OK" & @CRLF)

    Local $pPane1, $oPane1
    $oDesktop.FindFirst($TreeScope_Descendants, $pCondition0, $pPane1)
    $oPane1 = ObjCreateInterface($pPane1, $sIID_IUIAutomationElement8, $dtag_IUIAutomationElement8)
    If Not IsObj($oPane1) Then Return ConsoleWrite(':' & @ScriptLineNumber & ':' & " $oPane1 ERR" & @CRLF)
    ConsoleWrite(':' & @ScriptLineNumber & ':' & " $oPane1 OK" & @CRLF)

    ; --- Find combo box ---

    ConsoleWrite("--- Find combo box ---" & @CRLF)

    Local $pCondition1
    $oUIAutomation.CreatePropertyCondition($UIA_ControlTypePropertyId, $UIA_ComboBoxControlTypeId, $pCondition1)
    If Not $pCondition1 Then Return ConsoleWrite(':' & @ScriptLineNumber & ':' & " $pCondition1 ERR" & @CRLF)
    ConsoleWrite(':' & @ScriptLineNumber & ':' & " $pCondition1 OK" & @CRLF)

    Local $pComboBox1, $oComboBox1
    $oPane1.FindFirst($TreeScope_Descendants, $pCondition1, $pComboBox1)
    $oComboBox1 = ObjCreateInterface($pComboBox1, $sIID_IUIAutomationElement8, $dtag_IUIAutomationElement8)
    If Not IsObj($oComboBox1) Then Return ConsoleWrite(':' & @ScriptLineNumber & ':' & " $oComboBox1 ERR" & @CRLF)
    ConsoleWrite(':' & @ScriptLineNumber & ':' & " $oComboBox1 OK" & @CRLF)

    ; --- ExpandCollapse Pattern (action) Object ---

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

    Local $pExpandCollapsePattern1, $oExpandCollapsePattern1
    $oComboBox1.GetCurrentPattern($UIA_ExpandCollapsePatternId, $pExpandCollapsePattern1)
    $oExpandCollapsePattern1 = ObjCreateInterface($pExpandCollapsePattern1, $sIID_IUIAutomationExpandCollapsePattern, $dtag_IUIAutomationExpandCollapsePattern)
    If Not IsObj($oExpandCollapsePattern1) Then Return ConsoleWrite(':' & @ScriptLineNumber & ':' & " $oExpandCollapsePattern1 ERR" & @CRLF)
    ConsoleWrite(':' & @ScriptLineNumber & ':' & " $oExpandCollapsePattern1 OK" & @CRLF)

    ; --- ExpandCollapse Pattern (action) Methods ---

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

    $oExpandCollapsePattern1.Expand()
    ConsoleWrite(':' & @ScriptLineNumber & ':' & " $oExpandCollapsePattern1.Expand()" & @CRLF)

    Local $oUIElementArray1, $iLength1, $pElements ; $pElements is a pointer to an UI Automation element array

    Local $pTrueCondition
    $oUIAutomation.CreateTrueCondition($pTrueCondition)
    ConsoleWrite(':' & @ScriptLineNumber & ':' & " $oUIAutomation.CreateTrueCondition()" & @CRLF)
    If Not $pTrueCondition Then Return ConsoleWrite(':' & @ScriptLineNumber & ':' & " $pTrueCondition ERR" & @CRLF)
    ConsoleWrite(':' & @ScriptLineNumber & ':' & " $pTrueCondition OK" & @CRLF)


    $oComboBox1.FindAll($TreeScope_Children, $pTrueCondition, $pElements)

    $oUIElementArray1 = ObjCreateInterface($pElements, $sIID_IUIAutomationElementArray, $dtag_IUIAutomationElementArray)
    If Not IsObj($oUIElementArray1) Then Return ConsoleWrite(':' & @ScriptLineNumber & ':' & " $oUIElementArray1 ERR" & @CRLF)
    ConsoleWrite(':' & @ScriptLineNumber & ':' & " $oUIElementArray1 OK" & @CRLF)

    ; script stops here - apparently array is not created
    $oUIElementArray1.Length($iLength1)
    If Not $iLength1 Then Return ConsoleWrite(':' & @ScriptLineNumber & ':' & " $iLength1 = 0 ERR" & @CRLF)
    ConsoleWrite(':' & @ScriptLineNumber & ':' & " $iLength1 = " & $iLength1 & @CRLF)

    #cs=============================================================================
    Display array
    #ce=============================================================================
    Local $pElement1, $oElement1, $sValue1
    For $i = 0 To $iLength1 - 1
        $oUIElementArray1.GetElement($i, $pElement1)
        $oElement1 = ObjCreateInterface($pElement1, $sIID_IUIAutomationElement, $dtagIUIAutomationElement)
        $oElement1.GetCurrentPropertyValue($UIA_NamePropertyId, $sValue1)
        ConsoleWrite(':' & @ScriptLineNumber & ':' & " $sValue" & $i & "= " & $sValue1 & @CRLF)
    Next

    ; --- LegacyIAccessible Pattern (action) Object ---

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

    Local $pLegacyIAccessiblePattern1, $oLegacyIAccessiblePattern1
    $oComboBox1.GetCurrentPattern($UIA_LegacyIAccessiblePatternId, $pLegacyIAccessiblePattern1)
    $oLegacyIAccessiblePattern1 = ObjCreateInterface($pLegacyIAccessiblePattern1, $sIID_IUIAutomationLegacyIAccessiblePattern, $dtag_IUIAutomationLegacyIAccessiblePattern)
    If Not IsObj($oLegacyIAccessiblePattern1) Then Return ConsoleWrite("$oLegacyIAccessiblePattern1 ERR" & @CRLF)
    ConsoleWrite("$oLegacyIAccessiblePattern1 OK" & @CRLF)

    ; --- LegacyIAccessible Pattern (action) Methods ---
    ; tried to set value into combobox but nothing happens
    ConsoleWrite("--- LegacyIAccessible Pattern (action) Methods ---" & @CRLF)
    Local $sShowEntriesCombobox = 'All'
    $oLegacyIAccessiblePattern1.SetValue($sShowEntriesCombobox)
    ConsoleWrite("$oLegacyIAccessiblePattern1.SetValue()" & @CRLF)

    ; --- Selection Pattern (action) Object ---

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

    Local $pSelectionPattern1, $oSelectionPattern1
    $oComboBox1.GetCurrentPattern($UIA_SelectionPatternId, $pSelectionPattern1)
    $oSelectionPattern1 = ObjCreateInterface($pSelectionPattern1, $sIID_IUIAutomationSelectionPattern, $dtag_IUIAutomationSelectionPattern)
    Sleep(1000)
    If Not IsObj($oSelectionPattern1) Then Return ConsoleWrite(':' & @ScriptLineNumber & ':' & " $oSelectionPattern1 ERR" & @CRLF)
    ConsoleWrite(':' & @ScriptLineNumber & ':' & " $oSelectionPattern1 OK" & @CRLF)

    ; --- Selection Pattern (action) Methods ---

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

    $oSelectionPattern1.GetCurrentSelection($pElements)
    ConsoleWrite(':' & @ScriptLineNumber & ':' & " $oSelectionPattern1.GetCurrentSelection()" & @CRLF)


EndFunc   ;==>Example

Console Output

>"C:\Program Files (x86)\AutoIt3\SciTE\..\AutoIt3.exe" "C:\Program Files (x86)\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.au3" /run /prod /ErrorStdOut /in "C:\Users\Rod\Documents\AutoIt\jigsaw Show Entries Code\JIgsa Show Entries Combobox - for Forum 02.au3" /UserParams    
+>15:31:00 Starting AutoIt3Wrapper v.19.102.1901.0 SciTE v.4.1.2.0   Keyboard:00000409  OS:WIN_10/  CPU:X64 OS:X64  Environment(Language:0409)  CodePage:0  utf8.auto.check:2
+>         SciTEDir => C:\Program Files (x86)\AutoIt3\SciTE   UserDir => C:\Users\Rod\AppData\Local\AutoIt v3\SciTE\AutoIt3Wrapper   SCITE_USERHOME => C:\Users\Rod\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\Rod\Documents\AutoIt\jigsaw Show Entries Code\JIgsa Show Entries Combobox - for Forum 02.au3
+>15:31:00 AU3Check ended.rc:0
>Running:(3.3.14.5):C:\Program Files (x86)\AutoIt3\autoit3.exe "C:\Users\Rod\Documents\AutoIt\jigsaw Show Entries Code\JIgsa Show Entries Combobox - for Forum 02.au3"    
+>Setting Hotkeys...--> Press Ctrl+Alt+Break to Restart or Ctrl+Break to Stop
:18: $oUIAutomation OK
:25: $oDesktop OK
--- Find window/control ---
:35: $pCondition0 OK
:41: $oPane1 OK
--- Find combo box ---
:50: $pCondition1 OK
:56: $oComboBox1 OK
--- ExpandCollapse Pattern (action) Object ---
:66: $oExpandCollapsePattern1 OK
--- ExpandCollapse Pattern (action) Methods ---
:73: $oExpandCollapsePattern1.Expand()
:79: $oUIAutomation.CreateTrueCondition()
:81: $pTrueCondition OK
:88: $oUIElementArray1 OK
:92: $iLength1 = 0 ERR
+>15:31:00 AutoIt3.exe ended.rc:0
+>15:31:00 AutoIt3Wrapper Finished.
>Exit code: 0    Time: 1.681

Thanks in advance

Edited by rmckay
Typo

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