Sometimes it is annoying when there are multiple radio buttons and you want one in the middle of the list that isn’t always in the same place.
This is easily resolved by finding the correct radio button by searching for unique text.
So if the radio button is on the left hand side. to find the text in a row and then click the radio button you need an xpath that looks something like:
//td[text()=’SPECIFIC TEXT OF RADIO BUTTON’]/preceding-sibling::td/input[@type=”radio”]
This is assuming the <TD> tags are level with each other in the HTML.
Start logically by finding the text, then work your way backwards.
Another is using ancestor:
//span[text()=’SPECIFIC TEXT’]/ancestor::*/tr[@class=’CLASS NAME’]//td/img[@title=’TITLE NAME’]
//td[text()’SPECIFIC TEXT’]/ancestor::*/table[@id=’ID NAME’]//a[@title=’TITLE NAME’]
N.B. command = Click
Another example is to use parent and then following-sibling. In this example, I want to select the word Jeep from options in a drop down list (DDL):
<td>//td/a[contains(text(),’QA Portfolio Europe Jeep/Chry – Macclesfield’)]/parent::*/following-sibling::td/select</td>