ACCELQ simplifies the automation development by supporting the identification of web elements based on their textual/label-based attributes, instead of the usually unstable DOM structure. This eliminates the need for frequent maintenance efforts, as automation scripts are not impacted by changes to the application's front-end HTML.
The use of text-based commands makes the automation logic more readable and intuitive and allows for faster script development during sprints. To access these commands, simply type "label" in the logic editor or in the Recorder's (or View's) context menu.
Important Attributes of text-based identification
Two important attributes, Label and Anchor-text, play a crucial role when working with text-based commands.
The Label of an element for the purpose of text-based identification can be any visible text or otherwise relatable text on the element.
For example, it could be the label of an input field, the text on a button or link, placeholder text, etc. Sometimes, the label may be displayed as clear, visible text conventionally associated with a field (such as an input or dropdown), or it may be self-text for a link or button, or a placeholder for an input field.
Additionally, the label could be a hidden textual property as well. In the ACCELQ Recorder, if you hover over a particular element, you will see this hidden attribute displayed as "Text ID." This information comes in handy when developing logic with text-based elements.
Anchor text is any visible text which is closer to the element on the upper or left side can be used to resolve challenges with the uniqueness of the Label property.
This is optional. If not specified, during test execution the Label is searched across the page. If specified, the search for Label is limited to the area under/right of the Anchor text.
You may use any text on the upper/left side of the element to resolve this issue. The example below can use "Ship to different address" as the Anchor text for the "First name" we are interested in.
Operators for Label and Anchor Text
Both the Label value and Anchor text value can be specified not just as an exact matching text, but with a wide array of other operators. These are useful when the text in the Label or Anchor text is somewhat dynamic and variable. Here is the list of supported operators:
- equals, ignore case
- contains, ignore case
- starts with
- starts with, ignore case
- ends with
- ends with, ignore case
- matching regex
Examples of text-based automation approach
Here are some examples illustrating the vast applicability of this feature.
Enter text in an input field based on its label
In the example below, you could enter a value in the Username field using the label for the input field.
Enter text based on placeholder text
In the example below, you could enter a value in the Username field using the placeholder for the input field.
Select an item from a search dropdown
Text commands for searchable dropdowns support extensive capability to search for an item and select one of the resulting options. Selections based on the index are also supported in addition to pattern matching of options.
The following statement searches for "COB" text in the searchable dropdown and selects the second option from the resulting list. Note that the index starts with 1.
Clicking on an element based on the tooltip
In the image below, you will notice the edit icon has a tooltip "Edit Account Name". You can use the tooltip exactly the way that you would use visible text on the screen.
Clicking on a radio button option
The radio button option in the image below can be selected simply by providing the option name as clickable text.
Clicking on a link whose text is dynamic, but present under a known label
The Account Name link in the image below needs to be clicked as part of the automation logic. However, the text associated with the link is dynamic. To handle this scenario, you can create a click statement using a regular expression of ".*" (which matches any text) for the label, and specify an anchor text of "Account Name". This way, the automation logic can successfully click on the link, without relying on the actual account name.
Using dropdown commands for non-standard controls that allow selecting options with a click
Dropdown commands in ACCELQ can be used for any control that opens a list of options upon clicking, not just for conventional HTML dropdowns. As seen in the image below, the "Search Parameter" button opens a list of options that can be interacted with using the text-based dropdown commands.
Dealing with repeat elements
In the example below, the "Add to Cart" button is repeated multiple times for different product offerings. To accurately interact with the desired button, you can use the Anchor text to differentiate between instances of the repeating button and click the one you need.
Note: When recording or playing back a statement in the Design Studio, the system will warn you if it finds multiple labels that the statement is referring to. You can find this warning in the Design Studio console, and during playback, the element will blink in red in the Recorder browser.
You can review the warning and update the command with the appropriate anchor text to locate the desired instance of the element uniquely.
Click a Repeat Element where the Anchor text is variable
In the screenshot below, the Anchor text is variable but has a specific pattern (starts with). We can use the appropriate operator for the Anchor text to click the correct "Add to Cart" button here.
Clicking a repeat element based on the tooltip, and anchor text
In the screenshot below, you can click on the "Settings" icon for the "Internet" package by using a combination of the tooltip (as Label) and the Anchor text.
Note on conventional Element ID
Whenever possible, it is better to use text-based element identification as it simplifies both test development and maintenance. However, there may be situations where the conventional DOM-based element ID may be preferred due to the complexity of the logic involved.
Relying too heavily on textual positioning or content can be error-prone in certain cases, especially when working with complex container element structures. ACCELQ offers a structured, non-programming approach to simplify these kinds of element structures. Here is an article describing this with an example.
Please sign in to leave a comment.