dranzer006 Posted January 5, 2021 Share Posted January 5, 2021 Hi, I'm using UIAWrappers to make a script to select combobox inside a window. The app is made using WindowsForms10 and the ProcessIdPropertyId changes every time i restart the app. while CLASS name is same for all combobox The only permanent field that I can use is $UIA_AutomationIdPropertyId. is there any way/example to use this in _UIA_action Thanks Link to comment Share on other sites More sharing options...
dranzer006 Posted January 5, 2021 Author Share Posted January 5, 2021 PS: i am able to select the element using automationid:= however i can't choose the item in dropdown menu Link to comment Share on other sites More sharing options...
FrancescoDiMuro Posted January 5, 2021 Share Posted January 5, 2021 @dranzer006 Could you please post the entire UI tree from simplespy or UIASpy? dranzer006 1 Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette Link to comment Share on other sites More sharing options...
dranzer006 Posted January 5, 2021 Author Share Posted January 5, 2021 6 minutes ago, FrancescoDiMuro said: @dranzer006 Could you please post the entire UI tree from simplespy or UIASpy? Here https://pastebin.com/j2JCvU82 i am using _UIA_setVar("product","automationid:=CMBorder") _UIA_action("product","propertyvalue:=MKT, Market") is there something wrong in syntax ? Thanks Link to comment Share on other sites More sharing options...
FrancescoDiMuro Posted January 6, 2021 Share Posted January 6, 2021 Sorry @dranzer006. I am more familiar with UIASpy tool. Could you please download it and post the UI Tree? Otherwise, I am not of much help here (sorry again!) dranzer006 1 Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette Link to comment Share on other sites More sharing options...
dranzer006 Posted January 6, 2021 Author Share Posted January 6, 2021 52 minutes ago, FrancescoDiMuro said: Sorry @dranzer006. I am more familiar with UIASpy tool. Could you please download it and post the UI Tree? Otherwise, I am not of much help here (sorry again!) Here, I tried multiple ways (invoke, setfocus, click) however they don't select list box items directly . the only working solution I got was sending keyboard arrow keys directly to select, is there a better way to do this ? Thanks Link to comment Share on other sites More sharing options...
FrancescoDiMuro Posted January 6, 2021 Share Posted January 6, 2021 @dranzer006 Well, from here you could try to get the handle of the ComboBox with ControlGetHandle(), using the $UIA_AutomationIdPropertyId as the "NAME" (The internal .NET Framework WinForms name) of the control; otherwise, since the control supports theItemContainerPatter, maybee you can select the item with ItemContainerPattern.FindItem and select it from there Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette Link to comment Share on other sites More sharing options...
dranzer006 Posted January 6, 2021 Author Share Posted January 6, 2021 3 hours ago, FrancescoDiMuro said: @dranzer006 Well, from here you could try to get the handle of the ComboBox with ControlGetHandle(), using the $UIA_AutomationIdPropertyId as the "NAME" (The internal .NET Framework WinForms name) of the control; otherwise, since the control supports theItemContainerPatter, maybee you can select the item with ItemContainerPattern.FindItem and select it from there Thanks for the help can you give an example ? on older versions I used ControlCommand with selectstring, However its not supported in new .net apps Link to comment Share on other sites More sharing options...
FrancescoDiMuro Posted January 6, 2021 Share Posted January 6, 2021 @dranzer006 You should be able to see the ComboBox handle, and from there, we can operate in different ways: Spoiler expandcollapse popup#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 ;#AutoIt3Wrapper_UseX64=n ; If target application is running as 32 bit code ;#AutoIt3Wrapper_UseX64=y ; If target application is running as 64 bit code #include "UIA_Constants.au3" ; Can be copied from UIASpy Includes folder ;#include "UIA_Functions.au3" ; Can be copied from UIASpy Includes folder ;#include "UIA_SafeArray.au3" ; Can be copied from UIASpy Includes folder ;#include "UIA_Variant.au3" ; Can be copied from UIASpy Includes folder Opt( "MustDeclareVars", 1 ) Example() Func Example() ; Create UI Automation object Local $oUIAutomation = ObjCreateInterface( $sCLSID_CUIAutomation, $sIID_IUIAutomation, $dtag_IUIAutomation ) 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, $dtag_IUIAutomationElement ) If Not IsObj( $oDesktop ) Then Return ConsoleWrite( "$oDesktop ERR" & @CRLF ) ConsoleWrite( "$oDesktop OK" & @CRLF ) #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 ;#AutoIt3Wrapper_UseX64=n ; If target application is running as 32 bit code ;#AutoIt3Wrapper_UseX64=y ; If target application is running as 64 bit code #include "UIA_Constants.au3" ; Can be copied from UIASpy Includes folder ;#include "UIA_Functions.au3" ; Can be copied from UIASpy Includes folder ;#include "UIA_SafeArray.au3" ; Can be copied from UIASpy Includes folder ;#include "UIA_Variant.au3" ; Can be copied from UIASpy Includes folder Opt( "MustDeclareVars", 1 ) Example() Func Example() ; Create UI Automation object Local $oUIAutomation = ObjCreateInterface( $sCLSID_CUIAutomation, $sIID_IUIAutomation, $dtag_IUIAutomation ) 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, $dtag_IUIAutomationElement ) If Not IsObj( $oDesktop ) Then Return ConsoleWrite( "$oDesktop ERR" & @CRLF ) ConsoleWrite( "$oDesktop OK" & @CRLF ) ; --- Find window/control --- ConsoleWrite( "--- Find window/control ---" & @CRLF ) Local $pCondition0 $oUIAutomation.CreatePropertyCondition( $UIA_ProcessIdPropertyId, 924, $pCondition0 ) If Not $pCondition0 Then Return ConsoleWrite( "$pCondition0 ERR" & @CRLF ) ConsoleWrite( "$pCondition0 OK" & @CRLF ) Local $pListItem1, $oListItem1 $oParent.FindFirst( $TreeScope_Descendants, $pCondition0, $pListItem1 ) $oListItem1 = ObjCreateInterface( $pListItem1, $sIID_IUIAutomationElement, $dtag_IUIAutomationElement ) If Not IsObj( $oListItem1 ) Then Return ConsoleWrite( "$oListItem1 ERR" & @CRLF ) ConsoleWrite( "$oListItem1 OK" & @CRLF ) ; --- Condition to find window/control --- ConsoleWrite( "--- Condition to find window/control ---" & @CRLF ) Local $pCondition1 $oUIAutomation.CreatePropertyCondition( $UIA_NamePropertyId, "NAME OF THE WINDOW HERE", $pCondition1 ) ; NAME OF THE WINDOW HERE If Not $pCondition1 Then Return ConsoleWrite( "$pCondition1 ERR" & @CRLF ) ConsoleWrite( "$pCondition1 OK" & @CRLF ) ; --- Find window/control --- ConsoleWrite( "--- Find window/control ---" & @CRLF ) Local $pWindow1, $oWindow1 $oDesktop.FindFirst( $TreeScope_Children, $pCondition1, $pWindow1 ) $oWindow1 = ObjCreateInterface( $pWindow1, $sIID_IUIAutomationElement, $dtag_IUIAutomationElement ) If Not IsObj( $oWindow1 ) Then Return ConsoleWrite( "$oWindow1 ERR" & @CRLF ) ConsoleWrite( "$oWindow1 OK" & @CRLF ) ; Navigate until you reach the ComboBox with the same code after ConsoleWrite( "--- Find window/control ---" & @CRLF ), ; adapting the code for the various Controls ; ComboBox automation ; $oParent is the "UcNewBuySell" custom control Local $oParent, $pConditionN, $pComboBox, $oComboBox, $sAutomationID, $hComboBox $oParent.FindFirst( $TreeScope_Children, $pConditionN, $pComboBox ) $oComboBox = ObjCreateInterface( $pComboBox, $sIID_IUIAutomationElement, $dtag_IUIAutomationElement ) If Not IsObj( $oComboBox ) Then Return ConsoleWrite( "$oComboBox ERR" & @CRLF ) ConsoleWrite( "$oComboBox OK" & @CRLF ) $oComboBox.GetCurrentPropertyValue($UIA_AutomationIdPropertyId, $sAutomationID) $hComboBox = ControlGetHandle("Title of the Window", "", "[ID:" & $sAutomationID & "]") If IsHWnd($hComboBox) Then ConsoleWrite("Handle of the ComboBox = " & $hComboBox & @CRLF) EndFunc P.S.: you need to adapt the code to find the missing controls Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette Link to comment Share on other sites More sharing options...
LarsJ Posted January 6, 2021 Share Posted January 6, 2021 Note that the SelectionItemPattern is supported by the ComboBox control. The SelectionItemPattern is the correct way to handle selections. It's demonstrated in Example 11 of this post. As the ComboBox supports the SelectionItemPattern, there is a good chance that the list items are also supported. Then check the properties of the listitems. FrancescoDiMuro and dranzer006 2 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...
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