Differenciate radio buttons for getting the correct label

Hi,

I have 3 radio buttons for a specific field operationalInitiationVisaForecast:
I’m trying to check the label for each of the 3 radio buttons.

HTML:

<ux-form-control formcontrolname="operationalInitiationVisaForecast" formcontrolvalue="0" radiolabel="Forecast" class="">
<input type="radio" class="" id="ux-509748" name="operationalInitiationVisaForecast" value="0" tabindex="0">
<label class="" for="ux-509748">Forecast</label>
</ux-form-control>
<ux-form-control formcontrolname="operationalInitiationVisaForecast" formcontrolvalue="1" radiolabel="Real" class="">
<input type="radio" class="" id="ux-791383" name="operationalInitiationVisaForecast" value="1" tabindex="0">
<label class="radio-label ng-star-inserted" for="ux-791383">Real</label>
</ux-form-control>
<ux-form-control formcontrolname="operationalInitiationVisaForecast" formcontrolvalue="2" radiolabel="N/A" class="">
<input type="radio" class="" id="ux-929420" name="operationalInitiationVisaForecast" value="2" tabindex="0">
<label class="radio-label ng-star-inserted" for="ux-929420">N/A</label>
</ux-form-control>

I don’t know how to differentiate each radio button whose the name is operationalInitiationVisaForecast.

Could you help me with that ?

Although the name tags are the same, the id tags are different, so include the id tag in your identification of each button.
e.g. id=“ux-509748”, id=“ux-791383”, id=“ux-929420”

@grylion54 Hi, thanks for the response. But I cannot do that because the id can change and the test could not be working. Is there another solution ?

If the id tags change, what about using the value tag, or even possibly the formcontrolvalue tag? You need to find some reference that is unique to each.
e.g. value=“0”, value=“1”, value=“2”

Forecast:  //input[@name="operationalInitiationVisaForecast" and @value="0"]/following-sibling::label

Real:      //input[@name="operationalInitiationVisaForecast" and @value="1"]/following-sibling::label

N/A:       //input[@name="operationalInitiationVisaForecast" and @value="2"]/following-sibling::label

Use WebUI keyword to get label dynamically:

TestObject label = new TestObject().addProperty("xpath",
ConditionType.EQUALS,
"//input[@type='radio']/following-sibling::label")

String labelText = WebUI.getText(label)

Use parameterized Test Object:

  1. Create dynamic XPath:
//label[normalize-space()='${label}']/preceding-sibling::input

  1. Pass label as variable during execution.

Use CSS selector with value attribute:

input[type='radio'][value='Male']

Use relative XPath to identify label text:

//label[normalize-space()='Male']/preceding-sibling::input[@type='radio']

@stevio052002 How does getting the label "dynamically” assist the OP of determining which label to use? The issue was not getting the labels (plural) in a different way, but to get the labels in the first place as each “looked” similar to the others.

As the OP has a solution, which was to use two attributes, thank you for your thought(s). Also, yes the OP could have used only one Object to represent the three elements using parameterization, putting the value amount as an input reference–but small steps.

@stevio052002

You picked up this old topic which was already solved 5 years ago. Your action does not help anyone. It rather confuses others. Please stop excavating the ruins.

If you want to post something new and helpful, you should create a new topic on your own.

he is also create some duplicated topic/thread, a little bit spammy
fyi @nghi.phan @vu.tran @Elly_Tran