Article Overview:
This article will cover how you can achieve the following:
How to Target the intended element even though there are multiple elements with the same hint name.
Problem Statement:
The user is looking for an element with visible text on the page, but the default Hint selector targets a different element due to multiple instances of the same hint being present on the page.
Solution:
Virtuoso Test steps take multiple types of selectors (e.g., Hint,, Xpath, CSS) for their target elements.
Selectors are used by the order they are presented and the first selector that returns a valid element is used by Virtuoso.
If Virtuoso is interacting with a different element due to multiple instances of the same hint being present on the page, this issue can be resolved by following ways:
Using Relative position along with the Hints:
You can provide top, right, left, bottom hints (or a mix such as top right) to distinguish between multiple elements.
For example: Click on top "Login"
Using Element type along with the Hints and Relative positions (if needed):
When multiple elements of different types can match your query, you can provide more context to Virtuoso by providing the element type details to make better decisions.
Available element types are:
- link: Links such as <a> elements
- button: Buttons such as <button> or <input type="submit"> elements
- input: Input elements such as <input> or <textarea> elements
- image: Image elements such as <img> elements
- dropdown: Dropdowns such as <select> elements
- file: File input elements such as <input type="file"> elements or file drop zones
Note: In the natural language, the type always comes after the position.
For example: click on top right button "Login"
Using Deterministic selectors: CSS and Xpath
If none of the above techniques work, the deterministic selectors i.e. Xpath and CSS could be used to specifically target the element.
Using Disabling healing (This will ensure the position and properties of the element hasn’t changed and would target a specific element always)
In certain circumstances, e.g. when dealing with dynamic elements, It is preferable to rely only on Virtuoso's intelligent element selection, rather than the healing mechanism.
In these cases, you can lock the explicit element selectors on the step details panel.
Locking the explicit selectors can be useful when the element needs to be matched containing the provided text, as traditional selectors match elements by page structure and element classes.
Comments
0 comments
Please sign in to leave a comment.