Perzeptron Frequent Contributor.
Frequent Contributor.
204 views

How can I make a locator unique?

Jump to solution

How can I make a locator unique? I have the case that every week the data row increases by one. I want my test to always test the clickable link I recorded with the recorder. At the moment, however, the newly added data would always be checked because the locater and all other attributes are the same. Can I modify a locater and make it unique after recording?

My actual recorded locater is this:
//BrowserApplication//BrowserWindow//img[@title='abgeschlossen']

But next week it would be automatically to this:
//BrowserApplication//BrowserWindow//img[@title='abgeschlossen'][2]

I want the driver to identify the locater from the first week without having to edit the script and append a [2] to the locater

Or is it possible to combine two locaters? Something like that:
//BrowserApplication//BrowserWindow//img[@title='abgeschlossen'] and //BrowserApplication//BrowserWindow//span[@textContents='28.06.2019']

The date in the //span-locater would always be unique. But I don't how to combine locaters.

0 Likes
1 Solution

Accepted Solutions
Micro Focus Expert
Micro Focus Expert

Re: How can I make a locator unique?

Jump to solution

Hi

There are a few different ways to making a locator unique. However, without really knowing the structure/ hierarchy of your controls, I cannot for definite which would be best.

Are these controls within a HTML table?

Can you provide a screenshot of the controls?

The first suggestion would be to look for other unique attributes for the control rather than title. Is there an id attribute?

The second would be to identify a unique parent control and build a locator which traverses to the parent and back down to the child control. However, without knowing your controls, this may or may not be possible.

It is possible to construct a locator using multiple attributes, but it is not possible to build a locator using two different controls.

For example: If your //img control contained the attributes 'Title=abcedefg' and 'id=img_28-06-2019'' you could construct a locator like:

"//img[@title='abcdefg' and @Id='img_28-06-2019'"

Alternatively, you may want to look into using some of the other xpath subsets supported by Silk Test such as ancestor, following-sibling and preceding-sibling.

For more on these and all options, you can refer to the help topic:

https://documentation.microfocus.com/help/index.jsp?topic=%2Fcom.borland.silktest.workbench.doc%2FSILKTEST-B7043980-SUPPORTEDXPATHSUBSET-REF.html

Regards,
Colin

3 Replies
Micro Focus Expert
Micro Focus Expert

Re: How can I make a locator unique?

Jump to solution

Hi

There are a few different ways to making a locator unique. However, without really knowing the structure/ hierarchy of your controls, I cannot for definite which would be best.

Are these controls within a HTML table?

Can you provide a screenshot of the controls?

The first suggestion would be to look for other unique attributes for the control rather than title. Is there an id attribute?

The second would be to identify a unique parent control and build a locator which traverses to the parent and back down to the child control. However, without knowing your controls, this may or may not be possible.

It is possible to construct a locator using multiple attributes, but it is not possible to build a locator using two different controls.

For example: If your //img control contained the attributes 'Title=abcedefg' and 'id=img_28-06-2019'' you could construct a locator like:

"//img[@title='abcdefg' and @Id='img_28-06-2019'"

Alternatively, you may want to look into using some of the other xpath subsets supported by Silk Test such as ancestor, following-sibling and preceding-sibling.

For more on these and all options, you can refer to the help topic:

https://documentation.microfocus.com/help/index.jsp?topic=%2Fcom.borland.silktest.workbench.doc%2FSILKTEST-B7043980-SUPPORTEDXPATHSUBSET-REF.html

Regards,
Colin

Perzeptron Frequent Contributor.
Frequent Contributor.

Re: How can I make a locator unique?

Jump to solution

Hi  Colin,

yes, the controls are within a HTML table.

A screenshot is uploaded.

The attributes unfortunatelly are not unique, none oft hem. Therefor I can’t construct a locator which uses multiple attributes.

The only thing that comes to my mind is to use the grandfather element, which is unique. Unfortunately, I do not know how to do it. In the screenshot, I partly pixelated the text of the grandfather element. See the screenshot.:

11.png

0 Likes
Perzeptron Frequent Contributor.
Frequent Contributor.

Re: How can I make a locator unique?

Jump to solution

OK, Thank you. It was the trick with the ancestors. Here my solution, where I used wildcards and a substring from the link-text (a href). The <a href> Tag is the grandparent element and the <span> element is the parent element:

//BrowserApplication//BrowserWindow//a[@href='*DOKUMENT=228115658*']/span[@class='listnormal']/img[@title='abgeschlossen']


0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.