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

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