How to Create Dynamic XPath for Radio Button Selection?
There are two ways:
1) Using GUI Spy
Use GUI Spy to locate the radio button. It helps identify stable attributes (name, value, id, text) and provides the dynamic XPath.
2) Manually Writing Dynamic XPath
Inspect the radio button and create XPath using stable attributes. Common approaches:
-
Using attribute:
//input[@type='radio' and @value='Option1'] -
Using label text:
//label[text()='Option1']/preceding-sibling::input[@type='radio'] -
Using contains():
//input[@type='radio' and contains(@value,'Option')]
Note: It is recommended to use GUI Recorder or generate the step using GUI Spy for better accuracy and stability.