Categories

Using a non-unique locator

Some test configurations require that you can retrieve multiple elements of the same type with a single locator. There are several reasons for this:

Count the elements

It is useful to be able to count all elements of a given type to make sure without going into the details that a page, a table, a list, a search has the right number of elements.

We will take the example of a table that displays the main browsers and their porting on different operating system:

Our sample table: browsers / OS

We will make a first check that verifies that the number of lines is equal to 8.

We are looking at the lines (TR)

We will start by selecting a line, with an attribute that allows us to identify it, and we make sure to also identify one of his parents common to all the elements wi want to count in a unique way (starting with this one).

Select a unique line

Then we drag-drop the element following our script to make an occurrence check equal to 8.

The first check fails

Obviously, the first attempt to launch the test on the fly will fail, since this element is uniquely recognized with its xid = tr5, and thus Agilitest only finds one line occurrence.

We then remove the attribute TR xid = tr5 from the locator

Suppress the unique id specific to a single line

We obtain a non-exclusive locator which allows to find all the occurrences of TR under the element TABLE table-main

Check the number of lines in a TABLE element

When performing the action on the fly, we confirm that Agilitest finds 8 rows in this table.

If you click on the magnifying glass:

The magnifying menu

Agilitest displays all the elements that correspond to the locator used, as well as their order number of appearance in the structure of the tested software.

Search an item by its index

When we have locators that make it possible to find several elements, it is possible to specify by an index which we wish to address.

You wish to put an index on TR : click on TR


You must click in the editor on the item that is multiple

Then to the right of the element, you will see a # and two up / down controls that identify by an index the element defined by your locator.

Define an element by its index

By validating, Agilitest allows you to retrieve specific attributes of an element identified by its index. For example, we retrieve the text in the third line of the table below.


Retrieving the text contained in the 2nd row of the table

To go further

You can use the indexes on several elements of the same locator.

This can allow you for example to go check the contents of a specific cell of a table.

Get the text of a specific cell

This feature of identifying an element by its index can also allow you in some cases to get out of complex situations, if you lack attributes to uniquely select an item in a page.

You can also bring more robustness to your tests, for example if you often change your test data, to not select an item by its content but by its index may be more effective in the long run, but your test will be less deterministic.

Still require support?
Contact support