How to select a drop-down menu when the XPath IDs change with each page load

Good afternoon. I’m a novice Katalon Recorder user with limited programming experience.

I’m having trouble selecting a drop-down menu. I noticed that the XPath ID changes (F12 in Google Chrome) every time I load up the form. I believe this is called Dynamic Variable of Data Driven?

The labeling of the 2 drop down menu options are always consistent : “Private Passenger Auto” and “Commerical Truck” but the IDs in the Xpath seem to always have random numbers with each new load of the form. The URL is always the same, FYI

On the next page of the form, I am having trouble entering the First Name and Last Name because the X Path IDs change. For example, it will be named “id = LastName12344” then if I reload the form again it would be “id = LastName456456” so how can I get Katalon Recorder

Can you please help? I’m happy to provide screenshots and xpathcode using F12. I apologize in advance if this question has already been posted. Thank you

Katalon recorder 6.01
Windows 10 64 bit
Google Chrome

1 Like

Hi there,

Thank you very much for your topic. Please note that it may take a little while before a member of our community or from Katalon team responds to you.

Thanks!

As you have noted, dynamic attributes will change every time you load up the form. You may have to manually create a pathway for these objects. Since there is text within the last name’s <id> attribute that seems to be stable, for your pathway you could try:
//*[contains(@id, "LastName")]
or
//*[starts-with(@id, "LastName")]
(Note: I had to use the asterisk as you did not show the tag associated with the <id> attribute)

Perhaps you could do something similar with the first name.

Another idea is to review the HTML of the application and see if there are any other attributes, like <name> that is/are stable.

Edit: if the “dynamic” part of the <id> is in the center of the phrase, like “LastName_19_input”, then you can use two functions together, such as below. You can even use the same function, contains, twice in the statement, replacing starts-with.
//*[starts-with(@id, "LastName") and contains(@id, "_input")]
or
//*[starts-with(@id, "LastName")][contains(@id, "_input")]

2 Likes

Hi there, you can take this free course to get the basic knowledge of dealing with web test objects: [Free Course] How to Locate Web Elements for Automated Tests. Hope this helps.

A way I tend to approach issues like this is basically using approaches like what @grylion54 suggested, but a simple way to think about it is, find whatever is constant and use that (where you can). So, stuff like contains (or starts-with) when combined with whatever is constant (e.g. always there), tends to be a very quick way to find a relevant selector.

@guy.mason @grylion54

thank you both for your responses. Below or some screenshots and code to help you understand.

For example there are 4 results returning when you use the “contains” feature and then I use index [2] and it selects the right input field, but the zip code doesnt enter inside the katalon commands when I execute.

then I use index [2] and it selects the right input field, but the zip code doesnt enter inside the katalon commands when I execute.

here is another string which returns 1 result, but it doesnt enter the zip code

Maybe my steps are wrong inside Katalon? I am trying to enter zip code 20170

Please let me know if you have any questions. I apologize for my lack of knowledge

Instead of just using one attribute, you can use multiple attributes to try to isolate the pathway to your object so it is unique. As an example, along with <id>, you could also use <name> so you would have:

xpath=//*[contains(@id,'Id_GiveInitialZipCode_') and contains(@name,'Id_GiveInitialZipCode_') ]
1 Like

You can do as @grylion54 suggested in order to narrow things down, but in this case, you are also better off changing the Xpath to start with //input[contains…

You have a label (tag) with the identical ID above it, so if you try to ‘type’ into that, it won’t do anything either.

1 Like

@guy.mason @grylion54

I am still under to have Katalon enter the zip code. Maybe I misunderstood the code and where to place it. Could you be more specific on what to enter into the Command and Target columns?

When you fill the form manually, do you have to click on the “Zip” field first to give it focus, or do you just start typing when on the page? If you click on the “Zip” field, then you should add a click before your “sendKeys” event.

1 Like

Hi @grylion54 when the page loads, there is a flashing prompt where I can enter the zip code. No clicking needed. With that said, what kinds of commands should I enter in Katalon Recorder?

Thank you again for your help and @guy.mason too!

What do you want the commands to do (that it’s not yet doing)?

BTW Is there a particular reason that you enter a zip code both via ‘type’ and (a different one) via sendKeys? (e.g. does one work, but the other doesn’t?)

HI @guy.mason and @grylion54

My overall goal is to type the 5 digit zip code, but it doesn’t work when I run the case. If you run the individual steps (right click and select “play this step only” then it works. Its so strange.

What do you recommend? I already shared the screenshot with you on the current steps and neither of the steps are working. I appreciate your time in advance. Thank you

Difficult to say for certain without using the same website as you’re on, but it’s not unusual for certain text fields to only become ‘active’ once they are first selected, so you might want to try first clicking on the element (via the script), and seeing if this helps.

Some times things work when we select to play a specific state because from say mousing over it, clicking on it, or some other action, we’ve triggered the related JavaScript / state required for Katalon Recorder to then interact with that DOM element.