Jump to content

Recommended Posts

Posted

I'm pretty new to using the UIAWrapper.au3 and UI Automation. I'm working on automating a UI where I have a button without a title and I'm using a text box, which is child of the button to get at it. I'm able to get the button element and click on it, but every time I run the script when it finishes it gives the following error:

Autoit Crash.png

Here is my code:
 

#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <constants.au3>
#include <WinAPI.au3>
#include <debug.au3>
#include <CUIAutomation2.au3>
#include <UIAWrappers.au3>
#include <WinAPI.au3>
#include <WinAPISys.au3>

$cAppIdent = "title:=SomeProgram"
$oApp = _UIA_getFirstObjectOfElement($UIA_oDesktop, $cAppIdent, $treescope_children)

$oTW=ObjCreateInterface($UIA_pTW, $sIID_IUIAutomationTreeWalker, $dtagIUIAutomationTreeWalker)
Local $oparentHandle

$oParent=_UIA_getFirstObjectOfElement($oApp,"name:=Setu_p", $treescope_subtree)
$oTW.getparentelement($oParent,$oparentHandle) ;Get Parent button element
$oParentHandle=objcreateinterface($oparentHandle,$sIID_IUIAutomationElement, $dtagIUIAutomationElement)
$setupbutton = _UIA_getFirstObjectOfElement($oParentHandle,"class:=Button", $treescope_subtree)
_UIA_Action($setupbutton, "click")

Exit

 

Posted

I'm running on Windows 7 64bit. This is a company computer and I don't have access to inspect.exe. Below is the ouput from simplyspy. The MG ALFA application crashes if I try to spy certain areas of the UI that are blank and some buttons.

Mouse position is retrieved 43-180
At least we have an element title: [Setu_p] class: [TextBlock]

Having the following values for all properties: 
Title is: <Setu_p>  Class   := <TextBlock>  controltype:= <UIA_TextControlTypeId>   ,<50020>    , (0000C364)    29;174;23;12
*** Parent Information top down ***
4: Title is: <***Filepath Removed*** - MG-ALFA Version 10.4.2000>   Class   := <Window> controltype:= <UIA_WindowControlTypeId> ,<50032>    , (0000C370)    0;0;1920;1039
"Title:=***Filepath Removed*** - MG-ALFA Version 10.4.2000;controltype:=UIA_WindowControlTypeId;class:=Window"" 
3: Title is: <> Class   := <NavigationButtonMenu>   controltype:= <UIA_CustomControlTypeId> ,<50025>    , (0000C369)    3;135;75;871
"Title:=;controltype:=UIA_CustomControlTypeId;class:=NavigationButtonMenu"" 
2: Title is: <> Class   := <ListBox>    controltype:= <UIA_ListControlTypeId>   ,<50008>    , (0000C358)    3;137;75;871
"Title:=;controltype:=UIA_ListControlTypeId;class:=ListBox""    
1: Title is: <Milliman.LTS.UI.Core.Navigation.SimpleNavigationButton>   Class   := <ListBoxItem>    controltype:= <UIA_ListItemControlTypeId>   ,<50007>    , (0000C357)    4;138;73;65
"Title:=Milliman.LTS.UI.Core.Navigation.SimpleNavigationButton;controltype:=UIA_ListItemControlTypeId;class:=ListBoxItem""  
0: Title is: <> Class   := <Button> controltype:= <UIA_ButtonControlTypeId> ,<50000>    , (0000C350)    4;138;73;65
"Title:=;controltype:=UIA_ButtonControlTypeId;class:=Button""   


;~ *** Standard code maintainable ***
#include "UIAWrappers.au3"
AutoItSetOption("MustDeclareVars", 1)

_UIA_setVar("oP1","Title:=***Filepath Removed*** - MG-ALFA Version 10.4.2000;controltype:=UIA_WindowControlTypeId;class:=Window")   ;***Filepath Removed*** - MG-ALFA Version 10.4.2000
_UIA_setVar("oP2","Title:=;controltype:=UIA_CustomControlTypeId;class:=NavigationButtonMenu")   ;
_UIA_setVar("oP3","Title:=;controltype:=UIA_ListControlTypeId;class:=ListBox")  ;
_UIA_setVar("oP4","Title:=Milliman.LTS.UI.Core.Navigation.SimpleNavigationButton;controltype:=UIA_ListItemControlTypeId;class:=ListBoxItem")    ;Milliman.LTS.UI.Core.Navigation.SimpleNavigationButton
_UIA_setVar("oP5","Title:=;controltype:=UIA_ButtonControlTypeId;class:=Button") ;

;~ $oUIElement=_UIA_getObjectByFindAll("Setu_p.mainwindow", "title:=Setu_p;ControlType:=UIA_TextControlTypeId", $treescope_subtree)
_UIA_setVar("oUIElement","Title:=Setu_p;controltype:=UIA_TextControlTypeId;class:=TextBlock") ;ControlType:=UIA_TextControlTypeId;classname:=TextBlock")

;~ Actions split away from logical/technical definition above can come from configfiles 

;~_UIA_Action("oP1","highlight")
_UIA_Action("oP1","setfocus")
;~_UIA_Action("oP2","highlight")
_UIA_Action("oP2","setfocus")
;~_UIA_Action("oP3","highlight")
_UIA_Action("oP3","setfocus")
;~_UIA_Action("oP4","highlight")
_UIA_Action("oP4","setfocus")
;~_UIA_Action("oP5","highlight")
_UIA_Action("oP5","setfocus")

;~_UIA_action($oUIElement","highlight")
;~_UIA_action($oUIElement,"click")
;~_UIA_action("oUIElement","highlight")
;~_UIA_action("oUIElement","click")


;~ *** Standard code Flexible***
#include "UIAWrappers.au3"
AutoItSetOption("MustDeclareVars", 1)

Local $oP4=_UIA_getObjectByFindAll($UIA_oDesktop, "Title:=***Filepath Removed*** - MG-ALFA Version 10.4.2000;controltype:=UIA_WindowControlTypeId;class:=Window", $treescope_children)  
_UIA_Action($oP4,"setfocus")
Local $oP3=_UIA_getObjectByFindAll($oP4, "Title:=;controltype:=UIA_CustomControlTypeId;class:=NavigationButtonMenu", $treescope_children)   
Local $oP2=_UIA_getObjectByFindAll($oP3, "Title:=;controltype:=UIA_ListControlTypeId;class:=ListBox", $treescope_children)  
Local $oP1=_UIA_getObjectByFindAll($oP2, "Title:=Milliman.LTS.UI.Core.Navigation.SimpleNavigationButton;controltype:=UIA_ListItemControlTypeId;class:=ListBoxItem", $treescope_children)    
Local $oP0=_UIA_getObjectByFindAll($oP1, "Title:=;controltype:=UIA_ButtonControlTypeId;class:=Button", $treescope_children) 
;~ First find the object in the parent before you can do something
;~$oUIElement=_UIA_getObjectByFindAll("Setu_p.mainwindow", "title:=Setu_p;ControlType:=UIA_TextControlTypeId", $treescope_subtree)
Local $oUIElement=_UIA_getObjectByFindAll($oP0, "title:=Setu_p;ControlType:=UIA_TextControlTypeId", $treescope_subtree)
;~_UIA_action($oUIElement,"highlight")
_UIA_action($oUIElement,"click")


*** Detailed properties of the highlighted element ***
UIA_title:= <Setu_p>
UIA_text:= <Setu_p>
UIA_regexptitle:= <Setu_p>
UIA_class:= <TextBlock>
UIA_regexpclass:= <TextBlock>
UIA_iaccessiblechildId:= <0>
UIA_handle:= <0>
UIA_RuntimeId:= <7;10328;61956985>
UIA_BoundingRectangle:= <29;174;23;12>
UIA_ProcessId:= <10328>
UIA_ControlType:= <50020>
UIA_LocalizedControlType:= <text>
UIA_Name:= <Setu_p>
UIA_HasKeyboardFocus:= <False>
UIA_IsKeyboardFocusable:= <False>
UIA_IsEnabled:= <True>
UIA_ClassName:= <TextBlock>
UIA_ClickablePoint:= <40;180>
UIA_Culture:= <0>
UIA_IsControlElement:= <True>
UIA_IsContentElement:= <True>
UIA_IsPassword:= <False>
UIA_NativeWindowHandle:= <0>
UIA_IsOffscreen:= <False>
UIA_Orientation:= <0>
UIA_FrameworkId:= <WPF>
UIA_IsRequiredForForm:= <False>
UIA_IsDockPatternAvailable:= <False>
UIA_IsExpandCollapsePatternAvailable:= <False>
UIA_IsGridItemPatternAvailable:= <False>
UIA_IsGridPatternAvailable:= <False>
UIA_IsInvokePatternAvailable:= <False>
UIA_IsMultipleViewPatternAvailable:= <False>
UIA_IsRangeValuePatternAvailable:= <False>
UIA_IsScrollPatternAvailable:= <False>
UIA_IsScrollItemPatternAvailable:= <False>
UIA_IsSelectionItemPatternAvailable:= <False>
UIA_IsSelectionPatternAvailable:= <False>
UIA_IsTablePatternAvailable:= <False>
UIA_IsTableItemPatternAvailable:= <False>
UIA_IsTextPatternAvailable:= <False>
UIA_IsTogglePatternAvailable:= <False>
UIA_IsTransformPatternAvailable:= <False>
UIA_IsValuePatternAvailable:= <False>
UIA_IsWindowPatternAvailable:= <False>
UIA_ValueIsReadOnly:= <True>
UIA_RangeValueValue:= <0>
UIA_RangeValueIsReadOnly:= <True>
UIA_RangeValueMinimum:= <0>
UIA_RangeValueMaximum:= <0>
UIA_RangeValueLargeChange:= <0>
UIA_RangeValueSmallChange:= <0>
UIA_ScrollHorizontalScrollPercent:= <0>
UIA_ScrollHorizontalViewSize:= <100>
UIA_ScrollVerticalScrollPercent:= <0>
UIA_ScrollVerticalViewSize:= <100>
UIA_ScrollHorizontallyScrollable:= <False>
UIA_ScrollVerticallyScrollable:= <False>
UIA_SelectionCanSelectMultiple:= <False>
UIA_SelectionIsSelectionRequired:= <False>
UIA_GridRowCount:= <0>
UIA_GridColumnCount:= <0>
UIA_GridItemRow:= <0>
UIA_GridItemColumn:= <0>
UIA_GridItemRowSpan:= <1>
UIA_GridItemColumnSpan:= <1>
UIA_DockDockPosition:= <5>
UIA_ExpandCollapseExpandCollapseState:= <3>
UIA_MultipleViewCurrentView:= <0>
UIA_WindowCanMaximize:= <False>
UIA_WindowCanMinimize:= <False>
UIA_WindowWindowVisualState:= <0>
UIA_WindowWindowInteractionState:= <0>
UIA_WindowIsModal:= <False>
UIA_WindowIsTopmost:= <False>
UIA_SelectionItemIsSelected:= <False>
UIA_TableRowOrColumnMajor:= <2>
UIA_ToggleToggleState:= <2>
UIA_TransformCanMove:= <False>
UIA_TransformCanResize:= <False>
UIA_TransformCanRotate:= <False>
UIA_IsLegacyIAccessiblePatternAvailable:= <True>
UIA_LegacyIAccessibleChildId:= <0>
UIA_LegacyIAccessibleName:= <Setu_p>
UIA_LegacyIAccessibleRole:= <41>
UIA_LegacyIAccessibleState:= <0>
UIA_IsDataValidForForm:= <False>
UIA_ProviderDescription:= <[pid:10328,hwnd:0x0 Main(parent link):Unidentified Provider (managed:MS.Internal.Automation.ElementProxy, PresentationCore, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35)]>
UIA_IsItemContainerPatternAvailable:= <False>
UIA_IsVirtualizedItemPatternAvailable:= <False>
UIA_IsSynchronizedInputPatternAvailable:= <True>

Thanks for creating the UIA scripts, its helped me do what people in my office said was impossible.

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