Checking if the element exists Version 5 (Net)
Action group: Windows
Description
The action checks if the specified element exists on the screen.
Action icon
Settings of parameters
Property | Description | Type | Filling example | Mandatory field |
Parameters | ||||
Element | Resource with data of selected element in application | Robin.WinElement | Yes | |
Time-out | Time in milliseconds to find required element. | Robin.Numeric | No | |
Window order | Sequence number of the window that the action should work with. If you do not specify the window number, the first window will be checked. The numbering starts from 1. | Robin.Numeric | No | |
Results | ||||
Result | If the value is «true», the desired element exists. If the value is «false», the desired element does not exist. | Robin.Boolean | true |
Special conditions of use
The robot will return an error if:
- the window is not found,
- an invalid window number is entered.
The action searches the screen for the element requested by the user. The user enters the properties of the searched item in the "Item" field . The action returns the result "true" when the element is found. If the item is not found, the result of the action is "false".
If multiple items are found that match the specified parameters, the action should not cause an error. The action returns the value "true".
If the field specifies window number =1 and the item is in a different window, the action will return "false".
If the window number is specified outside the window number range (>), the first open window is interacted with.
If one window is open, the "Window number" parameter is ignored, no error will be thrown, BUT if a negative value is entered, the robot will return an error.
Window number | Number of windows | Robot interactions |
---|---|---|
Not filled in | Multiple (2+) | With the first open window |
Filled in correctly (1+) | Multiple (2+) | With the specified window |
Filled with invalid window number (10) | Multiple (2) | With the first open window |
Filled in correctly (1+) | 1 window | With the single window |
Filled with a negative number | 1 or multiple windows | Error |
The windows go in the order in which they were started.
Example of use
Task
There is an open window. Determine if the element exists on it.
Solution
Use the "Checking if element exists", "If", "Show message" actions.
Implementation
Move the "Checking if the element exists" action to the workspace and set its parameters.
Get the element using the WinSpy tool. Find more on how to work with the WinSpy in section Get Win-element.
Setting a timeout does not, in general, increase the execution time of an action beyond the time it takes for the item we are using in the action to become visible and accessible. During the set timeout, the action tries to access the element it is working with. As soon as the item is available, the waiting timeout expires.
Move the "If" action to the workspace and set its parameters.
In the "Condition" field specify the "Checking if the element exists" action result.
Move the "Show message" action to the "True" branch.
In the "Message text" field specify "Item found". This way, if an item is found in the window, the robot will display the message.
Move the "Show message" action to the "False" branch.
In the "Message text" field specify "Item not found". This way, if the item is not found in the window, the robot will display the message.
Click "Start" in the top panel. The final robot scheme will look like this:
Result
The program robot completed successfully.
The element is found. The robot displayed the appropriate message.