Jump to content
Sign in to follow this  
Kharizmah

IUIAutomation Getting Read-Only Selected Value from Combo Box

Recommended Posts

Kharizmah

Disabled WPF Combo Boxes are not selectable and cannot receive focus.

Despite that there is a value there and want to know if there is anyway to access it.

If I use Junkew's simplyspy.au3  both the program and simplespy.au3 will crash the moment I attempt to retrieve this combobox.

If I paste the capture before the crash, Simple Spy doesn't have any data registered for $UIA_SelectionSelectionPropertyId.

         AutoIt Error for simplyspy.au3:

---------------------------
AutoIt Error
---------------------------
Line 210  (File "E:\Program Files (x86)\AutoIt3\Examples\simplespy.au3"):

_UIA_DrawRect($t[1],$t[3]+$t[1],$t[2],$t[4]+$t[2])
_UIA_DrawRect($t[1],^ ERROR

Error: Array variable has incorrect number of subscripts or subscript dimension range exceeded.
---------------------------
OK   
---------------------------

If I use UI Spy or Inspect I do see a value named "list item" "Flat".

ComboxBox1.thumb.png.84ab66c5e4a4f27ced3

However, if I try:

 $comboBox.GetCurrentPropertyValue("SelectionSelection", $selection)

ConsoleWrite($selection)

Then ComboBox is highlighted but $selection is blank.

Is it imposible to retrieve this value when the comboBox is  disabled?

@junkew @LarsJ

Edited by Kharizmah

Share this post


Link to post
Share on other sites
Kharizmah

@junkew I might need clarification on this reply.

I do have administrator rights on the computer I am running the script from.

I tried inserting #requireadmin and looked for RunAs  and I am not seeing anything that would suggest that it needs to run in admin mode.

It works without crashing for all other fields except Read-Only WPF combo boxes.

In output it also has this line:

//TODO codetemplates.txt not available An error occurred when reading the file. & @CRLF

I'm not sure if that matters?

 

Edited by Kharizmah

Share this post


Link to post
Share on other sites
Kharizmah

That's what I posted above.  I do see the selected item using Inspect.exe

I'll try one more verification technique to ensure the correct object is being viewed. 

The previous one I tried is insuring the object was of class comboBox. I'll also verify the AutomationID this time and see if it's able to pull the value.

Share this post


Link to post
Share on other sites
Kharizmah

@junkew I cannot get any Selection data from that object.

 

Do you know if that's just the way it is for Disabled UI?

Is there a known way through AutoIt to do something like Snoop and Enable the object for reading and then Disable it later?

Try 2:

 

OutPut:

ComboBox exists!Selection: 

So, it finds this combobox but I can't get Selection.Selection data

Selection_Inspect.thumb.png.10539ec93cef

ComboBox exists!Selection:  Class: ComboBox Automation Id: OptionalEnum

I also tried If IsArray($selection) because apparently the return value is an array.

This also returns blank.  I was wondering if GetCurrentPropertyValue will only returns bools and singular values?

Edited by Kharizmah

Share this post


Link to post
Share on other sites
LarsJ

I can see, that the output in the png-image in first post is from UISpy.exe. You should not use UISpy.exe which is at least 10 years old and does not give any valuable information for newer applications. There is no direct connection between the information you get from UISpy.exe and the way you search for the same information through the UI Automation framework by junkew.

You should investigate the combo box with Inspect.exe. Then you'll probably see that Inspect.exe does not get the value in the combo box directly from the combo box but from an edit box which is a child control of the combo box. A combo box usually consists of an edit box and a list box.

With the information you get from Inspect.exe you can easily extract the same information through the UI Automation framework by junkew. And you'll probably see, that you have to extract the information from the edit box and not directly from the combo box.

Share this post


Link to post
Share on other sites
Kharizmah

@LarsJ

I generally do use Inspect.exe in conjunction with UISpy.exe and don't generally see a huge difference.

It saddens me that a program from 2003 can pull information that a newer one may not. 

I will install the latest Inspect.exe to see if that is true. Meanwhile here is Inspect from 2009.Selection_Inspect.thumb.png.10539ec93cef

As you can see there is still data showing in Selection.Selection

Edited by Kharizmah

Share this post


Link to post
Share on other sites
Kharizmah

@junkew It turns out it doesn't matter if it is enabled...

I will test a combo box  in a Windows app and get back to you

 

 

 

 

Edited by Kharizmah

Share this post


Link to post
Share on other sites
junkew

hard to say. I made a dummy WPF application with visual studio 2013 one disabled combobox and one enabled and run under windows 10

Simple spy gives this 

first one IsEnable is false and for second one its true.

Spy doesn't break

advice to comment out this in your version of simplespy: _UIA_DrawRect($t[1],$t[3]+$t[1],$t[2],$t[4]+$t[2]) 

unfortunately cannot share the latest version as mine is unstable at the moment

*** Detailed properties of the highlighted element ***
UIA_class:= <ComboBox>
UIA_regexpclass:= <ComboBox>
UIA_iaccessiblechildId:= <0>
UIA_handle:= <0>
UIA_RuntimeId:= <7;8388;35786431>
UIA_BoundingRectangle:= <171;136;120;22>
UIA_ProcessId:= <8388>
UIA_ControlType:= <50003>
UIA_LocalizedControlType:= <keuzelijst met invoervak>
UIA_HasKeyboardFocus:= <False>
UIA_IsKeyboardFocusable:= <False>
UIA_IsEnabled:= <False>
UIA_ClassName:= <ComboBox>
UIA_ClickablePoint:= <231;147>
 
*** Detailed properties of the highlighted element ***
UIA_class:= <ComboBox>
UIA_regexpclass:= <ComboBox>
UIA_iaccessiblechildId:= <0>
UIA_handle:= <0>
UIA_RuntimeId:= <7;8388;57957548>
UIA_BoundingRectangle:= <291;295;120;22>
UIA_ProcessId:= <8388>
UIA_ControlType:= <50003>
UIA_LocalizedControlType:= <keuzelijst met invoervak>
UIA_HasKeyboardFocus:= <False>
UIA_IsKeyboardFocusable:= <True>
UIA_IsEnabled:= <True>
UIA_ClassName:= <ComboBox>
UIA_ClickablePoint:= <351;306>
 

 

Share this post


Link to post
Share on other sites
Kharizmah

@junkew So I noticed that $UIA_SelectionSelectionPropertyId is missing from your capture.

It doesn't even show as blank.

When I comment out the _UIA_DrawRect($t[1],$t[3]+$t[1],$t[2],$t[4]+$t[2]) , I notice that $UIA_SelectionSelectionPropertyId is missing in my capture also.

So, with your wrapper will I be unable to capture this information?

I know that the return value of  $UIA_SelectionSelectionPropertyId is an array.

Yet I also see that scenario should be handled here:

 PropertyValueIsArray.thumb.png.b4aad89c5

 

Edited by Kharizmah

Share this post


Link to post
Share on other sites
Kharizmah

Okay, so just for fun, I changed the code to say:

If IsArray($tval) Then

_ArrayDisplay($tval)

EndIf

The return was an array of numbers:

Row|Col 0
[0]|1746
[1]|1086
[2]|120
[3]|21

 

Share this post


Link to post
Share on other sites
junkew

Its a safearray and to make life easier i make them a semicolon stringlist so easier to deal with under general assumption it are small arrays returned. I assume when you get the combobox itself you could play with a treewalker to iterate thru childs of the combobox beeing an edit and listcontrol. Of thise childcontrols you should be able to get the values.

Share this post


Link to post
Share on other sites
Kharizmah

@junkew Yes, when the ComboBox is enabled that is how I get the value.

After I select the ComboBox, I use Treewalker to view the children and select a child object or verify the object

$UIA_SelectionIsSelectionRequiredPropertyId = true

That workaround works fine for an enabled comboBox.

However, it does not work for a disabled comboBox.  

Edited by Kharizmah

Share this post


Link to post
Share on other sites
junkew
Kharizmah

@junkew

Okay apparently I do NOT fully read things.

Did you know that $UIA_SelectionSelectionPropertyId does NOT return as an array but as an IUIAutomationElementArray pointer.  That's why the _ArrayDisplay showed a series of numbers.

Okay... I see your above comment that's why you're suggesting using a ContainerPattern

 

Edited by Kharizmah

Share this post


Link to post
Share on other sites
Kharizmah

@LarsJ

In speaking with @junkew he suggested I try to access the $UIA_SelectionIsSelectionRequiredPropertyId by using an ItemContainerProvider.  I noticed you had assisted someone with something similar in the thread below.

I was wondering what the variables represented in your FindItemByProperty method are, as there are 4 variables and the MSDN https://msdn.microsoft.com/en-us/library/system.windows.automation.itemcontainerpattern.finditembyproperty(v=vs.110).aspx

only seem to be referring to 3 variables.

objectInterface_selection.thumb.png.6a6bIn changing the code around to reflect your example, $selection is showing a result of 0.

I can only assume this is because of the variables I am putting in.

Edited by Kharizmah

Share this post


Link to post
Share on other sites
LarsJ

Your link above refer to the function in the .NET framework. The functions which junkew implements are the functions in the Windows API. You can find the documentation for FindItemByProperty here.

Share this post


Link to post
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
Sign in to follow this  

  • Similar Content

    • spikespaz
      By spikespaz
      The rule against game automation is misguided and unhelpful for the following reasons.
       
      I am a developer, using AutoIt to automate testing for a game that I am developing. Singleplayer games can be mundane and sometimes cheating can be overlooked. Multiplayer games usually have anticheat against repetitive robotic actions anyways. People want to override the control schemes of games with bad customization. Eg. Axiom Verge, Fortnite (Crouching). Game automation is not always bad. If the user feels the need to automate a singleplayer game for boring or mundane tasks, that is their choice. Similarly, if I wish to use scripts to automate testing, that is my choice.
      Game automation can be a problem for online multiplayer games, giving players a competitive advantage. This could be countered by common sense; ask OP what game they are automating, and is it an online game? What is this script for, and what does it seem to do?

      Please revise the rule as it seems very unnecessary and harmful to people seeking help with innocent attempts at game automation.
    • milkmoron
      By milkmoron
      https://www.autoitscript.com/forum/topic/153520-iuiautomation-ms-framework-automate-chrome-ff-ie/?do=findComment&comment=1156373 At least we have an element title: [Entered By:] class: [WindowsForms10.EDIT.app.0.30495d1_r9_ad1] Having the following values for all properties: Title is: <Entered By:> Class := <WindowsForms10.EDIT.app.0.30495d1_r9_ad1> controltype:= <UIA_EditControlTypeId> ,<50004> , (0000C354) 322;370;736;184 *** Parent Information top down *** 3: Title is: <View Activity> Class := <WindowsForms10.Window.8.app.0.30495d1_r9_ad1> controltype:= <UIA_WindowControlTypeId> ,<50032> , (0000C370) 306;72;784;605 "Title:=View Activity;controltype:=UIA_WindowControlTypeId;class:=WindowsForms10.Window.8.app.0.30495d1_r9_ad1"" 2: Title is: <> Class := <WindowsForms10.Window.8.app.0.30495d1_r9_ad1> controltype:= <UIA_PaneControlTypeId> ,<50033> , (0000C371) 314;103;768;542 "Title:=;controltype:=UIA_PaneControlTypeId;class:=WindowsForms10.Window.8.app.0.30495d1_r9_ad1"" 1: Title is: <> Class := <WindowsForms10.Window.8.app.0.30495d1_r9_ad1> controltype:= <UIA_PaneControlTypeId> ,<50033> , (0000C371) 314;103;749;451 "Title:=;controltype:=UIA_PaneControlTypeId;class:=WindowsForms10.Window.8.app.0.30495d1_r9_ad1"" 0: Title is: <Delete> Class := <WindowsForms10.Window.8.app.0.30495d1_r9_ad1> controltype:= <UIA_PaneControlTypeId> ,<50033> , (0000C371) 314;122;749;432 "Title:=Delete;controltype:=UIA_PaneControlTypeId;class:=WindowsForms10.Window.8.app.0.30495d1_r9_ad1"" ;~ *** Standard code maintainable *** #include "UIAWrappers.au3" AutoItSetOption("MustDeclareVars", 1) _UIA_setVar("oP1","Title:=View Activity;controltype:=UIA_WindowControlTypeId;class:=WindowsForms10.Window.8.app.0.30495d1_r9_ad1") ;View Activity _UIA_setVar("oP2","Title:=;controltype:=UIA_PaneControlTypeId;class:=WindowsForms10.Window.8.app.0.30495d1_r9_ad1") ; _UIA_setVar("oP3","Title:=;controltype:=UIA_PaneControlTypeId;class:=WindowsForms10.Window.8.app.0.30495d1_r9_ad1") ; _UIA_setVar("oP4","Title:=Delete;controltype:=UIA_PaneControlTypeId;class:=WindowsForms10.Window.8.app.0.30495d1_r9_ad1") ;Delete _UIA_setVar("EnteredBy:.mainwindow","title:=Entered By:;classname:=WindowsForms10.EDIT.app.0.30495d1_r9_ad1") ;~ 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("EnteredBy:.mainwindow","setfocus") ;~ *** Standard code Flexible*** #include "UIAWrappers.au3" AutoItSetOption("MustDeclareVars", 1) Local $oP3=_UIA_getObjectByFindAll($UIA_oDesktop, "Title:=View Activity;controltype:=UIA_WindowControlTypeId;class:=WindowsForms10.Window.8.app.0.30495d1_r9_ad1", $treescope_children) _UIA_Action($oP3,"setfocus") Local $oP2=_UIA_getObjectByFindAll($oP3, "Title:=;controltype:=UIA_PaneControlTypeId;class:=WindowsForms10.Window.8.app.0.30495d1_r9_ad1", $treescope_children) _UIA_Action($oP2,"setfocus") Local $oP1=_UIA_getObjectByFindAll($oP2, "Title:=;controltype:=UIA_PaneControlTypeId;class:=WindowsForms10.Window.8.app.0.30495d1_r9_ad1", $treescope_children) _UIA_Action($oP1,"setfocus") Local $oP0=_UIA_getObjectByFindAll($oP1, "Title:=Delete;controltype:=UIA_PaneControlTypeId;class:=WindowsForms10.Window.8.app.0.30495d1_r9_ad1", $treescope_children) _UIA_Action($oP0,"setfocus") _UIA_setVar("EnteredBy:.mainwindow","title:=Entered By:;classname:=WindowsForms10.EDIT.app.0.30495d1_r9_ad1") _UIA_action("EnteredBy:.mainwindow","setfocus") Need some help selecting this defining it as a variable to save and then insert the text within, to the same application but different account.
    • TheSaint
      By TheSaint
      TeraCopy Timer - A program of mine, front end really, that I have been working on (on & off) for some time, but not shared here before, that I recall. Third party program TeraCopy is required.
      Many of you will be familiar with TeraCopy, and it has been discussed here at AF on several occasions, in various sub forums, including Chat.
      BE ADVISED - I still use an older version of TeraCopy (v2.27), a goody but an oldy, so have only tested my program with that. It may work with the newer v3.xx, or may be easily adjusted to do so, but I have not yet gone that route. Likewise, I only use it with Win 7 and Win XP, but I don't imagine there should be any issues with newer Windows. Add to that, my program being devised and created in AutoIt v3.3.0.0.
      So what is TeraCopy Timer and why might you need it?
      --------------------------------------------------------------------------------------
      Those familiar with TeraCopy use, know you can run multiple copy or move jobs either simultaneously or concurrently (one immediately after another has finished). With the free version at least, you have no control over precise order or timing, and no way to deal (without manual interaction) with the pesky Thumbs.db files in Win XP. TeraCopy Timer allows you to do all those things, and in a batch fashion.
      --------------------------------------------------------------------------------------
      Some screenshots and brief explanation
      Main Window
      Minimalist Window
      This new WAIT feature is the simplest and best way to use the program generally (in my view) ... but check out the following, as it is not always the case.
      Advanced Delay Window
      WARNING - It should go without saying, that you take all the usual precautions. For instance, don't use move with the only copy you have of precious files. BACKUP BACKUP BACKUP! Don't hold me liable for anything, except for being a nice guy who likes to share.
      TeraCopy Timer v2.8.zip  (see detail at Post #34)
      TeraCopy Timer v2.9.zip  (see detail at Post #35)
      Enjoy!
      OLDER DOWNLOADS
      P.S. I am not affiliated in any way with those who created and provide the excellent third party program - TeraCopy.
    • Earthshine
      By Earthshine
      This is pretty useful to me at least, I hope to others. Whenever you need to poke a button or such on a GUI, you can just make calls to this UDF and instruct it how long to wait, 0 is forever, anyway, let the code to the explaining. Feel free to help expand this UDF. I plan to create new ones as I go along that support all the Win32 and .NET Controls. Ultimately, I would like to be able to fully control any type of control, this works well with most. Just an example of what you can do.
       
      The test installs and can uninstall 7-Zip 15.14 (x64) Setup.exe
      NOTE: Logger Author(s) .....: Michael Mims (zorphnog)
      ;                    the logging script can be obtained here
      ;                   https://www.autoitscript.com/forum/topic/156196-log4a-a-logging-udf/
       
       
       
       
      WaitForControls.au3
      install_7zip_test.au3
    • rcmaehl
      By rcmaehl
      A UDF to connect and control Cisco Finesse on the Local Network via it's provided HTTP API
       
      Current Features:
      Heavyweight
      * Large feature set, containing most Finesse Desktop API functions  
      PLANNED Features:
      Heavyweight
      * Control over own Status as well as Supervisor functionality
        Helpful Premade Examples Files
      * Examples for almost every function
      * Premade CUI and GUI clients showing 
        Ready for all users, beginner and up
      * Detailed Error Reporting to help pin-point problems
      * Thorough parameter checking to prevent accidental script crashes
×