TestProject Forum

Trying to use ID as the main selector


I’m just starting to work with TestProject, and I’m trying to adapt our DOM generating framework to generate unique ID’s for all the elements, so that generating a test is easier for the recorder; at least that is the idea.

My problem is surely quite basic: suppose I have a main DIV with a unique ID that inside has a couple of nested divs and the inner one has a click handler. When I record a test, my goal would be to get a step definined by click on element with ID, or at least, click on elementWithID/DIV/DIV, but instead by default I get an XPath selector defining something like click on div[4]/div/div.

How can I change this behaviour, if possible, so that test recording takes ID’s more into account when recording a test, if not in the interacting element itself, at least looking up the tree for an element with a unique ID.

The structure of our page is quite likely to change quite often, not so the IDs of each element, so that’s why I’m trying to get this.

Thanks, and congratulations for your project

You can change create and add new locating strategies for the recorder to use when locating new elements from here:

It should look like this:

If XPath is changing a lot for you, you can choose to use only custom locators if possible

Another option would be to generate unique locators during the test I can use this button to create a locator for my element:

Then I can replace it in the element using the pencil to edit it:

Now I will replace the generated locator instead of the first one / or add a new one

Let me know if you managed

I have Locator type=ID enabled in my application, yet when I try to use it by identifying my element, it does not show in my dropdown as an option. Why is that?

Here are my Application settings:

If you want to use an ID as a locator, you need to use CSS SELECTOR (#)
For example:

Hello Amit,

Thanks for the response. I tried to edit location strategies with no luck, at least for the pourpouse I am heading. These are my settings now (I know they may not have lot of sense, but just trying): (Sorry, but I am only allowed to pust one image, so I will stick all the screenshots in one at the end of the post)


Now suppose I have a tab control that looks like, this; I want to select (and record) the Autozación tab item:


This is the step that gets recorded:


As you can see, no ID anywhwere. This is the structure of the DOM of the tab item:


As you can see, the element that has the ID is the li because I have no access to inner span, which is what gets selected when clicking on the tab item. I would like to be able to create a selector that selects the li, which is the one that as ID attribute. I also tried with a custom attribute (rpsid), with no luck. The selector recorded has a few problems: the content of the tab item can be changed, and also the order of the items can be changed.

I am aware that I can manually create an element that uses the selector I need (#id), but is there no way to the recorder to go up the DOM tree until it finds an element with an ID attribute? Or at least create an XPath like //elementWithCertainID/span[2], or something like that, more related to the unique ID I am generating.

Thanks again,

Thank you for your response. I will give that a try.

Hi @agarrenburu,
It seems like 2 screenshots are missing,
In any case please contact us via our designated live chat support which can be found on our application bottom right corner.