I need to automate a workflow and tried to rely on teststack white and UIA Verify to find the buttons in another application.
However when I try to identify the buttons I was greeted with just empty name properties for the controls inside the window I need to control (see attached screenshot).
The controls are apparently of type Custom.
I want to be able to press buttons and enter text into textboxes as well as check a checkbox.
Is there a way? Can I access them via for example an index (e.g. button = third control in window)?
Edit: As requested a screenshot from inspect.exe
Would you mind taking a look at those controls with Inspect.exe and posting a screen shot of the properites? You might be able to find another unique property on them to identify it with. Inspect.exe can be found C:\Program Files (x86)\Windows Kits\8.1\bin\x64\inspect.exe.
With White you wont be able to get a collection of all the buttons but with raw ui-automation you will be able to get a collection of the AutomationElements using FindAll.
Here is an example of how to get all controls of a certain type.
Retrieve Multiple UIItems ByClassName
Edit:
So after looking at the updated image from inspect I am afraid the application you are trying to automate didn't expose their application to ui-automation properly. I was certain that it wasn't exposed properly before but I was hoping they may have accidentally exposed some properties. I have seen this before with some 3rd party controls for VB6. It would be possible using the technique I linked above to get all the controls with a name of "" but then you would have to use the bounding rectangle property to move your mouse to the correct position and click (if that property is reporting the correct position) since I would wagger the invoke pattern is not supported. If you have access to the source code you could implement these properties and pattern.
Related
I apologize if the question isn't as accurate to what I want, but I'm fairly new to coding any type of window/form without a visual element or robust IDE (currently don't have access to Visual Studio, but want to begin work on a GUI while I wait as I have a bulk of the driving code done). I've had a difficult time finding out if/how this is possible due to the wording of my queries so far being too similar to other topics, like enabling/disabling buttons.
What I want is to emulate the programmatic functionality of adding buttons to a window present in the Revit API TaskDialog class. For those unfamiliar, this is a sample of how one creates a TaskDialog with a basic message and two buttons in C#:
TaskDialog dialog = new TaskDialog("Sample");
dialog.MainContent = "This is an example of how a TaskDialog is coded in the Revit API";
dialog.CommonButtons = TaskDialogCommonButtons.OK | TaskDialogCommonButtons.Close;
dialog.DefaultButton = TaskDialogResult.Close; // optional, will default to first button in box if unassigned
TaskDialogResult response = test.Show();
This type of framework would then be used on a window/form/user control that's used by multiple different modules, each with slightly different UI needs. Most modules will need a list box and Confirm/OK and Cancel buttons as a basis, but some will need additional buttons for additional functionality within the window.
If this functionality is better done in WinForms, I'm open to moving my GUI to that platform, I have interacted with both in the past and am somewhat familiar with the flow of each, just not the more advanced topics yet. This said, the data binding is an important feature for me, so wpf is preferred.
Any input would be greatly appreciated!
Edit
So, after some more digging around, I think I have a better understanding of how to ask my question:
What I want is the ability to programmatically add buttons (not RadioButtons like in this solution) to a window (wpf or winforms) by setting a variable in using the constructed window instance in the main code, passing it values from an enum with [Flags]. I want to have defined, common buttons (e.g. OK, Cancel, Close, etc) whose information and enum for adding to my window are in a module. I can then access these buttons through their enum, as Revit API allows with the TaskDialogCommonButtons enum, and assign them to a property of the window (in my example that would be the TaskDialog.CommonButtons property). This would then tell the window to show these buttons and none of the other buttons contained within the enum.
Unfortunately, the only results I get are how to data bind RadioButtons (not regular Buttons) that are then explicitly created within, or hard coded into, the xaml or codebehind of a window class and not dynamically added after the custom window class has been instantiated from the main code. This is clearly possible, otherwise the Revit API would not work in the way it does, but I can't seem to find anything relating to how or why it works and how to duplicate it.
Is simply a matter of including all of these buttons as hidden in the window class and using the enum to set the window instance's button visibility to show/true, thereby granting UI access? Or is it actually possible to add buttons programmatically from the driving code (not the codebehind of the window) using an enum?
Using UIAutomation on windows Forms, I'm trying to retrieve any control under mouse on a specific form.
The goal is to work on controls of an app, retrieving and acting on them.
The problem I'm facing since so many times is that I can't find a toolstripbutton.
Everytime I'm getting a pane (not parent nor child of the toolstripbutton I want, but parent's sibling).
This is the toolstripbutton I want to retrieve : .
The same control but in Inspect.exe (highlighted: the control I'm getting) :
I though that it was because of z order of the controls, then I tried using sibling controls, for controls where their bounds contains the mouse (for getting all controls under the cursor anyway their z order).
That fails because the toolstripbutton isn't retrieved.
I currently use UIAutomation and not CodedUI, because I need to run a custom program which retrieve controls and executes automatic tests on a specific server, but I actually have the Visual Studio Enterprise 2017 licence installed on my machine, but a second licence (for the server) and a third licence for a colleague for work with me on it would be a bit expensive.
Remembering that the programs have to retrieve dynamically the controls under the mouse, may someone gives me any idea which can help me to investigate deeper ?
Thanks & Greetings
Method used:
var aimed = AutomationElement.FromPoint(new System.Windows.Point(Cursor.Position.X, Cursor.Position.Y));
Solved by work around.
I made a recursive method that search deeper in the children for controls which contains the mouse (BoundingRectangle.Contains` method).
In that way, I can find the controls within the toolstrip.
But AutomationElement.FromPoint method doesn't search inside the toolstrip.
i'm writing because I have some hard times trying to get any automation-useful information about DevExpress controls. I do not have ability to see source code of application I'm testing, but UISpy and all other UI verifiers out there don't provide any information, including name, automationID and so on. The only thing that is available is info such as runtimeID, dynamically-assigned automationID and control type. Is there any chance to recognize these controls to get their unique properties? I know it must be some way since Visual Studio does that..
White is a wrapper for Microsoft's UI Automation Framework. As such, it uses Conditions on AutomationElemements' properties in order to find the appropriate element. UISpy is basically a visual reflection of what the UIA 'sees'. There are no other 'low level' properties.
Unfortunately, many developers and control vendors don't pay attention to setting a unique and indicative value for the AutomationID or Name properties, and thus make it hard to get the element you need.
The best solution I could give you is to create a helper method that works directly with UIA rather than with White, which gives you more flexibility in searching for your control. For example, if you have a DevExpress GridView, you could get all its child elements and query every single one of them for their relative position on the screen.
You could try with UI Automation Verify (UIA Verify). It will help you obtain the automationID.
I'm building a C# client app that allows a user to communicate with one or more existing users in a system via an email-like metaphor. I'd like to present the user with a text entry box that auto-completes on known email addresses, and allows multiple delimiter-separated addresses to be entered. Ideally, I'd also like the email addresses to turn into structured controls once they've been entered and recognized. Basically, I'm modeling the UI interaction for adding users after Facebook's model.
Are there any Windows Forms controls out there with the ability to do something like this? Is there any well-established terminology for a hybrid textbox / control list box (no, not a ComboBox) or something that I should be searching for?
Thanks,
-Patrick
I have had good luck in the past creating composite user-controls to provide specific functionality using native .NET Winforms controls. It works pretty good as long as there aren't too many of them, in which case things start to slow down.
In you case, and this is just off the top of my head, but, perhaps you could take a FlowLayoutPanel, a Button, and a Textbox which supports auto-complete and put these together to create a control that would provide the functionality you are looking for.
If there are no addresses selected in the control (e.g. in a List<string>), then the container (FlowLayoutPanel) would only display the TextBox. Once the user selected an entry, the control would automatically create a Button with the appropriate caption and insert it to the left in the FlowLayoutPanel. If the user removes an address he/she has already selected, simply remove its representation (the button) from the FlowLayoutPanel, and the TextBox can resize accordingly. There may be issues with getting the TextBox to fill up the remaining space (I can't remember how to do that), but you get the idea. The container does not have to be FlowLayoutPanel - you could use a Panel with Docked controls, or even a TableLayoutPanel for this.
A design as I described would allow the user to delete the address by clicking on the button. However, without some other visual cues, that isn't very intuitive or user-friendly, so I would consider making the "Button" be another composite control which contains a "prettied-up" label along with an tiny delete Button (X) to the right. For this you could use a Panel control and dock the X button to the right, and fill the Label on the left. You would provide public properties here as needed to control the text and provide an event handler or callback for the delete functionality.
Once the visual stuff is working, all that is left is to provide the appropriate Properties and Methods on the main control to allow it to interact as needed with outside code.
As a simple, "poor man's", implementation you could take a look at the AutoComplete* properties of the TextBox control. You could dynamically populate the AutoCompleteSource with your known addresses and when an entry matches, add to a separate, list-style control of your choice.
See this SO article for some interesting code snippets related to your question, and my suggested workaround.
Beyond the built-in AUtoComplete properties you're probably looking at having to purchase a 3rd party control from a tools vendor.
I've not seen anything like that before in WinForms. In WPF it would be another matter - if you can use that, maybe consider hosting a WPF control within your WinForms application instead?
I think you're trying to do something similar to this codeproject article: AutoComplete TextBox
And since you mention WPF in a comment, you also have this article: WPF AutoComplete Folder TextBox (should be easy enough to cut out the folder bit of the article I'd thought).
Well, there isn't such a control. If I were you, I'd create 2 textboxes to do the job. See, a normal textbox can easily be configured for autocomplete from a list, even dynamically; however, it accepts only one entry at a time.
So, I suggest you dedicate one textbox for autocomplete, and one for the addresses. So, whenever there is a qualified email address in the first textbox, and you click enter, the address gets added to the address textbox, and automatically add delimitation.
Then you need to handle the addresses in the address textbox as objects instead of characters. Code it in a way that when a user tries to delete a character in an address, the whole address is deleted.
This is the workaround I can think of. I'll help with the code if you give it a try.
i want to show the folder contents in my windows form from where user can copy paste the files user needed, what type of container i have to use for this purpose?
Basically you have two options. You can get an already build control and use it in your application, there are lots of them but not very good and you'll have to pay for one.
Or you could use a TreeView / ListView and build your own control that will suite best what you need. Here is an example explained and with source code.
Another alternative is you can get the Windows API Code Pack which contains a managed wrapper for the actual explorer shell control which basically allows you to embed explorer directly in your application.
before i used Ultra win tree(infrajestics control) to view all files with in the tree view.
Consider using the FolderView and FileView controls from Shell MegaPack.
Assuming :
the design requirements prohibit showing the actual location of the files the end-user can copy or paste. Assume all file names shown are stripped of their path locations.
the list of files is "flat" (no treeview type display is needed)
there's a need to move, or copy, one or more files from an original "complete" list to another "partial list"
I'd create an interface with two ListViews in a Panel : one column per ListView wide enough to display file names : allow multi-select in both of them.
I'd either implement drag-and-drop using standard techniques, or, more likely, I'd create a set of buttons with arrows to move items back and forth between the ListViews. I might have seperate delete buttons for each ListView and require the end-user to confirm deletion depending on the application.
If "multiple copies" (more than one list entry with identical content) are allowed I would probably use some keyboard options to control this, particularly if I were drag/dropping.
Depending on the application, I'd think about letting the end-user make "snapshots" of the current state of the two ListViews, which could then be "restored" : while a simple "Cancel" button could take care of the case where you want to reset the whole thing.