byname and bytext is an universal feature common for Web, UI Automation and WinForms (Managed) targets. Here we consider WinForms (.NET) desktop applications.
Consider the following Application Under Test (AUT):
Each item in the Managed object tree has Name and Text:
Normally, when Rapise learns an Object then element names are used for creating location path:
And trailing part of the path is Name of the object's element.
Note: An object name is detected by the heuristics. In this case heruistics knows that an element is a label so it assumes that its text may be used (in most cases labels contain static text) and checking this text becomes an additional object matching creteria.
In this case it is worth to update object location to reflect its semantics (set object ID to Category and element name is lblCategory):
As far as object matcher thinks that element't Text is an Object Name we should Ignore Object Name to true so it keeps working when Text changes.
Ignore Object Name
byname locator allows finding managed object by element name.
Element name in this case is lblCategory (last part of the learned locator). So in the example above we can modify the locator to use byname:
There is an extended syntax for the byname locator. We may use byname:N to say that the search should not go deeper than N element tree levels. Default depth level is 10.
So if we do: byname:5 it should not go to deep and work faster. If we do byname:15 it will go further in the elements tree and may work slower, but should find deeply nested widget.
There is another control on the same page: button OK. We need it to close the dialog and it has steady name:
It may be found wiht bytext locator as follows:
Rapise recorder tries to minimize unique values for the recorded object. For example, if object text is the same as object name then text one refers to name using param:object_name. If you want to use specific value then you may simply change param:object_name with actual value. I.e. &OK.
Each managed object has 2 entry points to enable recursive search:
DoFindByName(textOrRegexp, depth) Find nested element by its text (Value, Name of each element are compared with specified text or regular expression). See this Help Topic for reference.
DoFindByText(textOrRegexp, depth) Find nested element by its text (Value, Name of each element are compared with specified text or regular expression). See this Help Topic for reference.
// Find inbut box by name txtOrder and read its value
var orderTxt = SeS('Dialog').DoFindByName('txtOrder', 10);
Tester.Message('Order value: '+orderTxt.GetValue());
// Find button 'OK' and click.
var okBtn = SeS('Dialog').DoFindByText('regex:.*OK.*', 10);
Selected files will be attached to any email sent on saving ticket.
Select files to upload
Or drag and drop files here
Save to upload the selected file(s)