Xpath changes regularly

Hi Everyone, I have an issue. When I select an xpath and run the test sometimes the first few times it works. After sometime it fails, and when i go check the xpath again i discover that somethings in it has changed. This isn’t a web application that is being updated constantly . What do you think the problem could be?

for example the name in the code changes regularly . Here it is turnOverAvailableInd1 later it may become turnOverAvailableInd2.

<td>Is turnover figure available?</td>
<td valign="baseline">
<input type="radio" name="turnOverAvailableInd1" value="Y" onclick="javascript:turnOverAvailableToggle(this);" id="turnOverAvailableInd1Yes">YES
<input type="radio" name="turnOverAvailableInd1" value="N" onclick="javascript:turnOverAvailableToggle(this);" id="turnOverAvailableInd1No">NO     
</td>

This is how i select the radio button
Select Radio Button turnOverAvailableInd1 N

Some web applications are developed using systems which autogenerate various parts of the page, in particular name, ids and other element attributes. Some older, but still used Microsoft technologies are like this. I have seen them change on a page load. If you have a communication channel with the developers for this site you are testing, starting a conversation about making the site testable I would think greatly benefit both you and them. If that is not the case, for most elements I then find a method to avoid using these changing attributes and locators. This being a radio button for which the builtin Select Radio Button keyword takes name and value that becomes a bit more problematic as you must use the name and value attributes. Worse case scenario, if these keep changing and they can’t be changed such that this does not change frequently, then you could use a more stable locator that doesn’t use the name/value pair and instead make you own clicker. Never the best solution but might be the best option if the name keep changes. (I much prefer to use the select radio buttons because it does some checks internally to see if it is selected or not).

Seeing as “Select Radio Button” is just expecting a name for the group, perhaps you could first figure out the name with something like Get Element Attribute?

You could use “Get Element Attribute” to find out the name of your field using a partial xpath search for the text you know does not change. Something like this perhaps:

${group_name}=    Get Element Attribute         //input[contains(@name, 'turnOverAvailableInd')]    name
Select Radio Button    ${group_name}    N
1 Like