Jump to content

UI Automation - Loop through children


mkander
 Share

Recommended Posts

Hi! 

I am working on automating a program we use at work. I need to select the correct row in a table. I have found the table in UIASpy. All rows are listed as children of the table in UIASpy. 

Is there any way to loop through the children of an element? I locate the table by UIA_NamePropertyId, just need a way to loop through children now.

Thanks for all help!

Magnus

Link to comment
Share on other sites

There will be a major update in a week or two mainly about sample code creation. After that more advanced topics as you are facing will be treated. Hopefully within a month or so.

Regards Lars.

Link to comment
Share on other sites

  • 1 month later...
  • 1 year later...

I do have the same issue now. There is a "FindAll" instead of "FindFirst" which should work, however I have no Idea how to handle the AutomationelementCollection in autoIt

https://docs.microsoft.com/de-de/dotnet/api/system.windows.automation.automationelement.findall?view=netcore-3.1#System_Windows_Automation_AutomationElement_FindAll_System_Windows_Automation_TreeScope_System_Windows_Automation_Condition_

I could not find any "access nth child"-method either. The TreeScope does not have a Siblings Value or similar, so this does not work either.

Link to comment
Share on other sites

Thank you. By now I basically ripped the code from UISpy for this task. I dont know yet why switches by Windows Version for $sIIDIUIAutomationElement and $dtagIUIAutomationElement - I used Win 7 parameters and it worked on Win 10. However the following does GetCurrentPropertyValue for all children of $oParent (if anyone else needs this for future tasks):
 

$oParent.FindAll($TreeScope_Children, $pCondition, $pChilden)
    If Not $pChilden Then Return ConsoleWrite("$pChilden ERR" & @CRLF)
    ConsoleWrite("$pChilden OK" & @CRLF)

    Local $oAutomationElementArray, $iLength
    $oAutomationElementArray = ObjCreateInterface($pChilden, $sIID_IUIAutomationElementArray, $dtag_IUIAutomationElementArray)
    $oAutomationElementArray.Length($iLength)
    If Not $iLength Then Return ConsoleWrite("$iLength ERR" & @CRLF)

    Local $sIIDIUIAutomationElement, $dtagIUIAutomationElement
    $sIIDIUIAutomationElement = $sIID_IUIAutomationElement
    $dtagIUIAutomationElement = $dtag_IUIAutomationElement

    Local $pItem, $oItem
    For $i = 0 To $iLength - 1
        $oAutomationElementArray.GetElement($i, $pItem)
        $oItem = ObjCreateInterface($pItem, $sIIDIUIAutomationElement, $dtagIUIAutomationElement)
        $oItem.GetCurrentPropertyValue($field_name,$value)
    Next

 

Edited by wljdflgio
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...