Jump to content

UIAutomation getParentElement of located object


 Share

Recommended Posts

I have been successfully automating a WPF program using the UIAWrapper.au3 file.

However some panel elements appear in panels to where they need to be scrolled down to.

Nevertheless, I can still invoke buttons and access fields that are not visible on screen.

The problem comes with the datagrid.  I can locate the grid, dump all the children and locate the specific element by the text in the field.

It will locate it in the panel even if it is not on screen. However, I cannot select it using _UIA_action if it isn't visible. As it is part of a row and not a button, I cannot invoke it.

The parent element has no unique identifiers. 

 

The parent element has a row element.

Since I can locate the element by text. Is there someway that I can say,  $thisElement.GetParentElement($oParent) or $thisElement.GetFirstAncestor($oParent)

My hope is through this I can get the Row where that element falls.  Then I can select the first grid element and arrow down to that row.

 

 

 

Edited by Kharizmah
Link to comment
Share on other sites

It's alright I found a workaround.

I just iterate through the children by row.

Then for each row look for the text in it's children. This option is slow, but it works. 

I was hoping I could just look all the way straight down for the child and then up to getParent to figure out the row#.

 @junkew

Edited by Kharizmah
Link to comment
Share on other sites

  • Moderators

@Kharizmah please take note of where you're posting in the future; the Examples forum you posted in clearly states it is not a General Support forum. I have moved your thread to the appropriate forum.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

  • Moderators

@Kharizmah, the IUIAutomation post you were in is in the Examples forum, so when you hit Start New Topic, guess where it places it? Not an issue, just something to keep in mind for the future; with your topic in the correct forum you will get more eyes on the problem, and more people to assist :)

 

 

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

if you have an element it should not be hard to get the parent. Its just a treewalker. Study simplespy.au3 its exactly doing what you want

1. ctrl+w identifies the element

2. get a treewalker

3. pas your known element to the treewalker getparentelement method

spy then iterates thru all parents and grandparents until desktop is found

;~ consolewrite("Element from point is passed, trying to convert to object ")
    $oUIElement = objcreateinterface($UIA_pUIElement,$sIID_IUIAutomationElement, $dtagIUIAutomationElement)

;~ Walk thru the tree with a treewalker
    $UIA_oUIAutomation.RawViewWalker($UIA_pTW)
    $oTW=ObjCreateInterface($UIA_pTW, $sIID_IUIAutomationTreeWalker, $dtagIUIAutomationTreeWalker)
    If IsObj($oTW) = 0 Then
        msgbox(1,"UI automation treewalker failed", "UI Automation failed failed",10)
    EndIf

;~  at least 1 assumed (assuming we are not spying the desktop)
    $i=0
    $oTW.getparentelement($oUIElement,$oparentHandle[$i])
    $oParentHandle[$i]=objcreateinterface($oparentHandle[$i],$sIID_IUIAutomationElement, $dtagIUIAutomationElement)
    If IsObj($oParentHandle[$i]) = 0 Then
        msgbox(1,"No parent", "UI Automation failed could be you spy the desktop",10)
    Else

 

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

×
×
  • Create New...