Help files

Building UI Selectors

The UI selectors are very useful when using UI/Windows actions, as they help you access any windows/elements you want.

UI selectors are generated for each control you add in your Control Repository and can be shown should you double click on a Control.

WinAutomation automatically generates one selector for each control, but additional selectors can be added, in sequential order. This means that, if the first selector fails to access the element, then we fall back to the second selector; and in case of a new failure we fall back to the third and so on. The action will error out if none of the selectors are able to get the element and there is no Exception handling in the relative tab of the action's properties.

You do have the option to modify the existing generated selectors (delete one or two of them, enhance them, or build them yourself from scratch) so that you can get the desired window or element.

Let’s say that you have an “Untitled – Notepad” window open on your desktop which you wish to get.

Selectors are read from left to right using “>” to show that the element that follows in contained within the previous one in a "parent > child" notion. Let’s say that you want to access a Notepad Window and then click on the File Menu option.

You would have to use a "Click Element in Window" action and add the Control to the Repository. You will end up with the control as follows:

buildinguiselectors1png.png

The Window 'Untitled-Notepad' will have its selectors and once accessed the Process will move on to the Menu Item:File for this window.

What if you want to get a text document with another specific name??

Double click on the Window 'Untitled-Notepad' and in the window that pops up hit the Edit button for each selector.

builduiselectors2.png

In the selector builder Window that will appear you can check other attributes that you want to include in the existing Selector for the window. Thus, the selector will become more complex.

builduiselectors3.png

OR, you can choose to build a Custom Selector form the drop down list menu option on the top left part of the Selector Builder window.

In general the selector for a specific window with "n" attributes is:

:desktop >   window[Attribute1=”Attribute1Name”][Attribute2=”Attribute2Name”]...[Attributen=”AttributenName”]

So, for the notepad with title "Untitled" the selector can be:

:desktop > window[process="Notepad"][name="Untited - Notepad"][class="Notepad"]

...you can delete one or more attributes and you can just keep the ones that you think will make your selector more efficient, in the Selector Builder Window.

builduiselectors4.png

Using Variables in Selectors:

If you have a variable that holds the name of the text file then in the Custom Selector you can insert that variable. Let's say that you are certain that the file you want to access is named "Example.txt".

The selector to access that window can simply be:

:desktop > window[process="Notepad"][name=" Example "][class="Notepad"]

or

:desktop > window[name=" Example "][process="Notepad"]

Further on, if you have the name of the file in a variable like %FileName%=Example then the selector can be:

:desktop >  window[process="Notepad"][name=" %FileName% "][class="Notepad"]

Useful Tips for more efficient Selectors:

:desktop > window[name ^= ”Untitled”][process=”notepad”]

would get any Notepad window that its title starts with “Untitled”.

:desktop > window[name $= ”Notepad”][process=”notepad”]

would get any Notepad window that its title ends with Notepad.

:desktop > window[name ~= ”Untitled”][process=”notepad”]

would get any Notepad window that contains the word Untitled in its title.

:eq(n) is a very frequently used selector attribute. It selects the element at index "n" within the matched set (keep in mind that it always zero based). If the index is negative then the (|n| – 1) element is picked counting from the last element to the first.

For example if you have several buttons in a window and you write something like:

…> button:eq(0) >… this means that you are looking for the first button, while button:eq(1) would be the second button and button:eq(2) would be the third one and so on.