I have an issue. When I select an xpath and run the test sometimes the first few times it works. After some time 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
CodePudding user response:
You can use the other locator like, ID
, CSS Selector
or different XPATH
like below
//input[@id='turnOverAvailableInd1Yes'] // For YES radio button
//input[@id ='turnOverAvailableInd1No'] //For NO radio button
OR
You can use the Value like below
//input[@value='Y'] //For YES radio button
//input [@value= 'N'] //For NO radio button
OR
//*[contains(text()='YES')] //For YES radio button
//*[contains(text()='NO')] //For NO radio button
You can find more here
CodePudding user response:
If I understand your question correctly, you want an xpath that can work whether then name is "turnOverAvailableInd"
appended by some number. If so, the following xpaths could work:
//input[@value='Y' and contains(@name,'turnOverAvailableInd')]
//input[@value='N' and contains(@name,'turnOverAvailableInd')]