I am using K6 to test a web page, on one of the pages it returns radio selection options.
I am wanting to capture all the available options returned in that page and select one of them for the next request I send.
I can do this using the ".html().find(“input[name=nameofradio]”).attr(“value”) which works however this only ever finds the first radio entry, how can I access the others?
Thanks
Ian
Hi @hirstian02 , Welcome to the community forum!
I don’t know the exact html you have, but something like this may help you:
page.$$('input[name="radioName"]').forEach(input => console.log(input.getAttribute('value')));
If this doesn’t help, please share the sanitized version of the html + script with us.
Sorry I didnt make it clear, I just used a generic term of web page.
I am not using K6 Browser, I am using the notmal K6,
This is the K6 request:
let res = http.post(‘https://urlofapp.co.uk/application-name/customer ’, { _csrf: csrfToken, customerID: ‘123456’});
This is an extract of the radio buttons from the returned html, these are dynamic based on each customer:
<div class="aa-radios__item">
<input class="aa-radios__input" id="interactiontype" name="interactiontype" type="radio" value="Incoming telephone call">
<label class="aa-label aa-radios__label" for="interactiontype">
Incoming
</label>
</div>
<div class="aa-radios__item">
<input class="aa-radios__input" id="interactiontype-2" name="interactiontype" type="radio" value="Outgoing telephone call">
<label class="aa-label aa-radios__label" for="interactiontype-2">
Outgoing
</label>
</div>
hirstian02:
Incoming telephone call
Sorry, I forgot to say that I am wanting to be able to capture the Values ie “Incoming telephone call” etc
@hirstian02 : Sorry for the misundestanding, then this will help you
resp.html().find('input[name=interactiontype]').toArray().forEach(item => console.log(item.attr('value')));
Thank You so much that worked