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 Controls Repository and can be shown should you double click on a Control.


WinAutomation automatically generates one or more selectors. 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.


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 is 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:



The Window 'Untitled-Notepad' will have its selectors and once accessed the Process will move on to the MenuItem: File ofthis window.


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


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



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


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:

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


So, for the notepad with title "Untitled" the selector can be:
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.



- 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:

window[process="Notepad"][name="Example.txt - Notepad"][class="Notepad"] 

or 

window[name="Example.txt - Notepad"][process="Notepad"] 


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

window[process="Notepad"][name="%FileName%.txt - Notepad"][class="Notepad"]



· Useful Tips for more efficient Selectors: 


window[name^=”Untitled”][process=”notepad”]
would get any Notepad window that its title starts with “Untitled”.


window[name$=”Notepad”][process=”notepad”]
would get any Notepad window that its title ends with Notepad.


window[name~=”Untitled”][process=”notepad”]
would get any Notepad window that contains the word Untitled in its title.



NOTE:


: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 is 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.