I have some radio buttons on an application and I would like to write a JavaScript function to select the appropriate radio button. When I inspect the code behind the page, I see a lot of nested elements where each radio button is a div class and each div contains the Label. For example:
<div data-test-automation-id="roleRadio4312028" class="form-element form-group">
<div class="form-control__container outlined">
<div class="radio">
<label title="">
<input name="roleId" variant="1" type="radio" data-test-automation-id="input" value="4312028">
<span data-test-automation-id="label" class="">Radio Button 1</span>
</label>
</div>
</div>
</div>
<div data-test-automation-id="roleRadio4312028" class="form-element form-group">
<div class="form-control__container outlined">
<div class="radio">
<label title="">
<input name="roleId" variant="1" type="radio" data-test-automation-id="input" value="4312028">
<span data-test-automation-id="label" class="">Radio Button 2</span></label>
</div>
</div>
</div>
How do I write a javascript function to effectively select the radio button I want? I would like to run this function in the console to ensure the correct radio button is selected.
The javascript function that I am thinking of is:
function selectRadioButton(choice){
//document.getElementById OR document.getElementByName()
}
Thanks in advance