We've got some poorly written radio buttons on a legacy page as follows:
<input id="button1" name="button" value="32" onchange="assignProduct(this.value);" type="radio"></input>
RADIO TEXT 1
<input id="button2" name="button" value="33" onchange="assignProduct(this.value);" type="radio"></input>
RADIO TEXT 2
for information, this displays the same as would:
<input id="button" name="button" value="32" onchange="assignProduct(this.value);" type="radio">RADIO TEXT 1</input>
<input id="button" name="button" value="33" onchange="assignProduct(this.value);" type="radio">RADIO TEXT 2</input>
The latter code is more correct and allows selection of input button by text "RADIO TEXT 2" by:
driver.findElement(By.xpath("(//input[contains(@text, 'RADIO TEXT 2')])")).click();
What code can I use to find the radio button in the first code sample, which is what I actually have to deal with?
The text is no longer contained within the element so .xpath() doesn't match it.
I need to find the text, then click the input immediately prior? Can I do this without consuming and traversing the entire page?