Lycan Posted January 7, 2019 Share Posted January 7, 2019 Hi all! I'm trying to set up some basic automation / load-testing scripts for one of our vendor supplied apps and am stumbling over something I hope you can help with. So the app pulls up many windows, one of which is a diagram window. I can identify the window ok I need to zoom out on this window. There is a nice little textbox area along the bottom that allows you to select the zoom level which I hope to make use of but I am having difficulty selecting this and changing its text. The default zoom is 0.910 value and I would like to change that value to 0.050 When I run the GetAllWindowControls function supplied by another member on this forum (apologies I can't find the member whose post I found it from), it shows me 2 different sets of controls based upon if I click directly in the textbox or if I click anywhere else along the status bar. See below. When clicking in the textbox: Func=[GetAllWindowsControls]: ControlCounter=[ 1] ControlID=[6554636] Handle=[0x0064040C] ClassNN=[WindowsForms10.EDIT.app.0.232467a_r13_ad11] XPos=[ 177] YPos=[1558] Width=[ 40] Height=[ 14] IsVisible=[1] Text=[0.910]. Func=[GetAllWindowsControls]: ControlCounter=[ 2] ControlID=[1706344] Handle=[0x001A0968] ClassNN=[WindowsForms10.Window.8.app.0.232467a_r13_ad11] XPos=[ 0] YPos=[ 93] Width=[2560] Height=[1458] IsVisible=[1] Text=[splitContainerControl2]. Func=[GetAllWindowsControls]: ControlCounter=[ 3] ControlID=[3738006] Handle=[0x00390996] ClassNN=[WindowsForms10.Window.8.app.0.232467a_r13_ad12] XPos=[ 0] YPos=[ 93] Width=[2560] Height=[1458] IsVisible=[1] Text=[Panel1]. Func=[GetAllWindowsControls]: ControlCounter=[ 4] ControlID=[1182288] Handle=[0x00120A50] ClassNN=[WindowsForms10.Window.8.app.0.232467a_r13_ad13] XPos=[ 0] YPos=[ 93] Width=[2560] Height=[1458] IsVisible=[1] Text=[]. ... When clicking anywhere else along the status bar: Func=[GetAllWindowsControls]: ControlCounter=[ 1] ControlID=[1706344] Handle=[0x001A0968] ClassNN=[WindowsForms10.Window.8.app.0.232467a_r13_ad11] XPos=[ 0] YPos=[ 93] Width=[2560] Height=[1458] IsVisible=[1] Text=[splitContainerControl2]. Func=[GetAllWindowsControls]: ControlCounter=[ 2] ControlID=[3738006] Handle=[0x00390996] ClassNN=[WindowsForms10.Window.8.app.0.232467a_r13_ad12] XPos=[ 0] YPos=[ 93] Width=[2560] Height=[1458] IsVisible=[1] Text=[Panel1]. Func=[GetAllWindowsControls]: ControlCounter=[ 3] ControlID=[1182288] Handle=[0x00120A50] ClassNN=[WindowsForms10.Window.8.app.0.232467a_r13_ad13] XPos=[ 0] YPos=[ 93] Width=[2560] Height=[1458] IsVisible=[1] Text=[]. Func=[GetAllWindowsControls]: ControlCounter=[ 4] ControlID=[4785560] Handle=[0x00490598] ClassNN=[WindowsForms10.Window.8.app.0.232467a_r13_ad14] XPos=[ 0] YPos=[ 93] Width=[2560] Height=[1458] IsVisible=[1] Text=[]. Some of the various methods I have tried are as follows: ControlClick ControlSetText ControlSend MouseClick Send All to no avail, I can't even get the cursor to select the text box area. Here is some snippets of the relevant code I have tried: - ; Change the magnification level to 0.500 WinActivate($DispHwnd) $WinLoc = WinGetPos($DispHwnd) WinWaitActive($DispHwnd) WinSetOnTop($DispHwnd,"",1) WinSetState($DispHwnd,"",@SW_MAXIMIZE) MouseMove($WinLoc[0]+($WinLoc[2]/2),$WinLoc[1]+($WinLoc[3]/2),20) ; ControlSend($DispHwnd, "", "[CLASS:WindowsForms10.EDIT.app.0.232467a_r13_ad1; INSTANCE:1]", "0.050") Local $ZoomCtrl = ControlGetHandle($DispHwnd, "", "[WindowsForms10.EDIT.app.0.232467a_r13_ad11]") ControlSetText($DispHwnd, "", "[CLASS:WindowsForms10.EDIT.app.0.232467a_r13_ad1; INSTANCE:1]", "0.050") - ControlClick($DispHwnd, "", "[NAME:diagram]", "Left",1,210,1045) Opt("MouseCoordMode", 0) MouseClick("Left",1,210,1045) Opt("MouseCoordMode", 1) - Opt("MouseCoordMode", 0) ;WinActivate($DispHwnd) ;WinWaitActive($DispHwnd) MouseClick("left","31", "5",1,"") ControlSetText($DispHwnd, "", $ZoomCtrl, "0.050") MouseClick("left","76", "720",2,"") Opt("MouseCoordMode", 1) According to UISpy, the elements details are as follows: Treeview Element Button: 1.000 Element Properties (identification) $UIA_ControlTypePropertyId $UIA_ButtonControlTypeId $UIA_NamePropertyId 1.000 Element Properties (information) $UIA_BoundingRectanglePropertyId l=2729,t=1389,w=70,h=22 $UIA_HasKeyboardFocusPropertyId False $UIA_IsContentElementPropertyId True $UIA_IsControlElementPropertyId True $UIA_IsDataValidForFormPropertyId False $UIA_IsEnabledPropertyId True $UIA_IsKeyboardFocusablePropertyId True $UIA_IsOffscreenPropertyId False $UIA_IsPasswordPropertyId False $UIA_IsRequiredForFormPropertyId False $UIA_LocalizedControlTypePropertyId button $UIA_ProcessIdPropertyId 856 $UIA_ProviderDescriptionPropertyId [pid:856,hwnd:0x0 Main(parent link):Microsoft: MSAA Proxy (unmanaged:uiautomationcore.dll)] Control Patterns (element actions) $UIA_IsInvokePatternAvailablePropertyId True $UIA_IsLegacyIAccessiblePatternAvailablePropertyId True Control Pattern Properties $UIA_LegacyIAccessibleChildIdPropertyId 0 $UIA_LegacyIAccessibleDefaultActionPropertyId Edit $UIA_LegacyIAccessibleDescriptionPropertyId Current Scale $UIA_LegacyIAccessibleHelpPropertyId $UIA_LegacyIAccessibleKeyboardShortcutPropertyId $UIA_LegacyIAccessibleNamePropertyId 1.000 $UIA_LegacyIAccessibleRolePropertyId 43 $UIA_LegacyIAccessibleStatePropertyId 1048576 $UIA_LegacyIAccessibleValuePropertyId Parents from Desktop Pane: Desktop Window: Network Display Pane: Dock Bottom StatusBar: Status Bar Parent to child index 2 Any assistance would be appreciated. Link to comment Share on other sites More sharing options...
Lycan Posted January 7, 2019 Author Share Posted January 7, 2019 Please excuse the redaction, I have underlined in red the appropriate area/section I wish to change. Link to comment Share on other sites More sharing options...
Lycan Posted January 8, 2019 Author Share Posted January 8, 2019 So a bit more information. I have downloaded and run inspect.exe (this is running on Windows 7 SP1 x64) and that little textbox is actually a button entitled "1.000". When you click on the button, an "Editing control" => "Editing control" submenu becomes visible in which is the value I wish to change (0.910). This "Editing control" => "Editing control" is completely not visible until you click on the 1.000 button (which would explain why my treesearches aren't working). See attached screenshots. Link to comment Share on other sites More sharing options...
Lycan Posted January 8, 2019 Author Share Posted January 8, 2019 As can be seen here, before clicking on/in the "1.000" button there is no "Editing control" tree item. Link to comment Share on other sites More sharing options...
LarsJ Posted January 8, 2019 Share Posted January 8, 2019 This means that you need to use a 2-step procedure to set the value in the edit control: 1. Click "1,000" button 2. Set edit value You can try this code: expandcollapse popup#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 ;#AutoIt3Wrapper_UseX64=y ; If Network Display is running as a 64 bit application ;#AutoIt3Wrapper_UseX64=n ; If Network Display is running as a 32 bit application Opt( "MustDeclareVars", 1 ) #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 ) ; --- Network Display window --- ConsoleWrite( "--- Network Display window ---" & @CRLF ) Local $pCondition ; $UIA_NamePropertyId is LOCALIZED and maybe CASE SENSITIVE $oUIAutomation.CreatePropertyCondition( $UIA_NamePropertyId, "Network Display", $pCondition ) If Not $pCondition Then Return ConsoleWrite( "$pCondition ERR" & @CRLF ) ConsoleWrite( "$pCondition OK" & @CRLF ) Local $pNetworkDisplay, $oNetworkDisplay $oDesktop.FindFirst( $TreeScope_Descendants, $pCondition, $pNetworkDisplay ) $oNetworkDisplay = ObjCreateInterface( $pNetworkDisplay, $sIID_IUIAutomationElement, $dtagIUIAutomationElement ) If Not IsObj( $oNetworkDisplay ) Then Return ConsoleWrite( "$oNetworkDisplay ERR" & @CRLF ) ConsoleWrite( "$oNetworkDisplay OK" & @CRLF ) ; Window handle Local $hHandle $oNetworkDisplay.GetCurrentPropertyValue( $UIA_NativeWindowHandlePropertyId, $hHandle ) ConsoleWrite( "$hHandle = " & Ptr( $hHandle ) & @CRLF ) ; --- Click "1.000" button --- ConsoleWrite( "--- Click ""1.000"" button ---" & @CRLF ) Local $pCondition1 $oUIAutomation.CreatePropertyCondition( $UIA_ControlTypePropertyId, $UIA_ButtonControlTypeId, $pCondition1 ) If Not $pCondition1 Then Return ConsoleWrite( "$pCondition1 ERR" & @CRLF ) ConsoleWrite( "$pCondition1 OK" & @CRLF ) Local $pCondition2 ; $UIA_NamePropertyId is LOCALIZED and maybe CASE SENSITIVE $oUIAutomation.CreatePropertyCondition( $UIA_NamePropertyId, "1.000", $pCondition2 ) If Not $pCondition2 Then Return ConsoleWrite( "$pCondition2 ERR" & @CRLF ) ConsoleWrite( "$pCondition2 OK" & @CRLF ) ; And condition $oUIAutomation.CreateAndCondition( $pCondition1, $pCondition2, $pCondition ) If Not $pCondition Then Return ConsoleWrite( "$pCondition ERR" & @CRLF ) ConsoleWrite( "$pCondition OK" & @CRLF ) Local $pButton, $oButton $oNetworkDisplay.FindFirst( $TreeScope_Descendants, $pCondition, $pButton ) $oButton = ObjCreateInterface( $pButton, $sIID_IUIAutomationElement, $dtagIUIAutomationElement ) If Not IsObj( $oButton ) Then Return ConsoleWrite( "$oButton ERR" & @CRLF ) ConsoleWrite( "$oButton OK" & @CRLF ) Local $pInvoke, $oInvoke $oButton.GetCurrentPattern( $UIA_InvokePatternId, $pInvoke ) $oInvoke = ObjCreateInterface( $pInvoke, $sIID_IUIAutomationInvokePattern, $dtagIUIAutomationInvokePattern ) If Not IsObj( $oInvoke ) Then Return ConsoleWrite( "$oInvoke ERR" & @CRLF ) ConsoleWrite( "$oInvoke OK" & @CRLF ) $oInvoke.Invoke() Sleep( 1000 ) ; --- Set Edit value --- ConsoleWrite( "--- Set Edit value ---" & @CRLF ) $oUIAutomation.CreatePropertyCondition( $UIA_ControlTypePropertyId, $UIA_EditControlTypeId, $pCondition1 ) If Not $pCondition1 Then Return ConsoleWrite( "$pCondition1 ERR" & @CRLF ) ConsoleWrite( "$pCondition1 OK" & @CRLF ) $oUIAutomation.CreatePropertyCondition( $UIA_NamePropertyId, "Editing control", $pCondition2 ) If Not $pCondition2 Then Return ConsoleWrite( "$pCondition2 ERR" & @CRLF ) ConsoleWrite( "$pCondition2 OK" & @CRLF ) ; And condition $oUIAutomation.CreateAndCondition( $pCondition1, $pCondition2, $pCondition ) If Not $pCondition Then Return ConsoleWrite( "$pCondition ERR" & @CRLF ) ConsoleWrite( "$pCondition OK" & @CRLF ) Local $pEdit, $oEdit $oNetworkDisplay.FindFirst( $TreeScope_Descendants, $pCondition, $pEdit ) $oEdit = ObjCreateInterface( $pEdit, $sIID_IUIAutomationElement, $dtagIUIAutomationElement ) If Not IsObj( $oEdit ) Then Return ConsoleWrite( "$oEdit ERR" & @CRLF ) ConsoleWrite( "$oEdit OK" & @CRLF ) Local $pValue, $oValue $oEdit.GetCurrentPattern( $UIA_ValuePatternId, $pValue ) $oValue = ObjCreateInterface( $pValue, $sIID_IUIAutomationValuePattern, $dtagIUIAutomationValuePattern ) If Not IsObj( $oValue ) Then Return ConsoleWrite( "$oValue ERR" & @CRLF ) ConsoleWrite( "$oValue OK" & @CRLF ) $oValue.SetValue( "0.500" ) EndFunc Controls, File Explorer, ROT objects, UI Automation, Windows Message MonitorCompiled code: Accessing AutoIt variables, DotNet.au3 UDF, Using C# and VB codeShell menus: The Context menu, The Favorites menu. Shell related: Control Panel, System Image ListsGraphics related: Rubik's Cube, OpenGL without external libraries, Navigating in an image, Non-rectangular selectionsListView controls: Colors and fonts, Multi-line header, Multi-line items, Checkboxes and icons, Incremental searchListView controls: Virtual ListViews, Editing cells, Data display functions Link to comment Share on other sites More sharing options...
Lycan Posted January 8, 2019 Author Share Posted January 8, 2019 Wow thanks LarsJ, I would never have got such detailed code :-o Would you believe I got it to work just before I left work - though very rough and nothing quite as elegant (as you can see, code modified from SimpleSpy): Local $oP3=_UIA_getObjectByFindAll($UIA_oDesktop, "Title:=Network Display;controltype:=UIA_WindowControlTypeId;class:=WindowsForms10.Window.8.app.0.232467a_r13_ad1", $treescope_children) ;_UIA_Action($oP2,"setfocus") Local $oP2=_UIA_getObjectByFindAll($oP3, "Title:=Dock Bottom;controltype:=UIA_PaneControlTypeId;class:=WindowsForms10.Window.8.app.0.232467a_r13_ad1", $treescope_children) ;_UIA_Action($oP1,"setfocus") Local $oP1=_UIA_getObjectByFindAll($oP2, "Title:=Status Bar;class:=WindowsForms10.Window.8.app.0.232467a_r13_ad1", $treescope_children) Local $oP0=_UIA_getObjectByFindAll($oP1, "Title:=1.000;ControlType:=button", $treescope_children) ;_UIA_Action($oP0,"invoke") if not isObj($oP0) Then ConsoleWriteError("Error with oP0" & @CRLF) _UIA_Action($oP0,"click") Send("^a") Send("0.015") Send("{ENTER}") Once I've clicked in the controlI found I could just "send" the commands. My apologies for not updating the thread earlier but I had to run out of work to catch the train as I had stayed back a few extra minutes trying to get the code to work (which it did) and didn't have a chance to update this thread. Typical though, work on something for days (yes, sad I know, days) and finally post on the support forum only to figure something working out a few hours later. Link to comment Share on other sites More sharing options...
Lycan Posted January 8, 2019 Author Share Posted January 8, 2019 ok I thought I'd use your code because it's too elegant to waste :-) Just a small glitch though, it changes the value but doesn't hit ENTER so the diagram doesn't change.. is there an elegant way of doing that? Then on to my next problem (another post) - detecting when the zoom finishes by finding if a another progress bar "button"/control is visible/enabled.. *sigh* Link to comment Share on other sites More sharing options...
Lycan Posted January 8, 2019 Author Share Posted January 8, 2019 hmmmmm actually I just need to click anywhere outside of the control to get it to change the zoom... might use something less elegant to achieve that goal :-) Link to comment Share on other sites More sharing options...
Lycan Posted January 8, 2019 Author Share Posted January 8, 2019 ok, pretty simple when you look at it. Just added a send("ENTER") after the setvalue. Not as elegant as your solution but does the trick :-) Thanks again LarsJ Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now