Radio Button not selected with Click

Hi!

I am using Browser Library with Robot Framework in my work. I am trying to create a test script for document, which is using Radio Button selection. Used Keyword is below:

Keyword for Radio Button Action
Wait For Elements State xpath=//[starts-with(@value,“Value of Radio Button”)] visible timeout=2s
Click xpath=//
[starts-with(@value,“Value of Radio Button”)] delay=100ms

I have tried a few tricks already, but it seems selecting this Radio Button is not successful. Any suggestions, how could I solve it?

Thank you!

One more thing. This is screenshot from console. Blue painted is Radio Button text.
image

Hi Kalle,

do you get an error or warning in your log? what was the message?

Something to try:

Click xpath=//[starts-with(@value,“Value of Radio Button”)]/..

This will click the <span> above the <input> which might be blocking the <input> from receiving the click

You might need to even click the <label> or even the <label>'s parent, depending on your site’s HTML and CSS

Hope that helps,

Dave.

Hi

Thanks for reply. I got this kind of warning:

I have also tried to click label, but so far I haven’t find out solution, which could work.

Hi Kalle,

As I suspected the message in the log is telling you there are other elements covering the element you are trying to click.

On the first try it was a <span class="mat-radio-container">, on the second try it was a <div> with a class of footer

You might need to scroll the page so the radio button is not covered before trying to click it. It’s also a good idea to let the page finish loading before interacting with it to prevent these types of issues.

Dave.

Hi

Thanks. Your help was valuable. Now it seems to click Radio Button successfully, or so report says. However, the state of the Radio Button is still this:
image

It should be this:
image

Have you tried Check Checkbox keyword? It should work for radio buttons and as it does not perform click, overlapping elements shouldn’t be a problem. And it does not deselect the radio button if it was already selected.
Wait For Elements State shouldn’t be needed, because it is in-built in Browser keywords.

Hi

Thanks for the tip. I tried that. However, I got this kind of error message after that:

Error: locator.check: Clicking the checkbox did not change its state

=========================== logs ===========================
waiting for locator(‘xpath=//*[@id=“mat-radio-3”]/label/span[1]’)
locator resolved to
attempting click action
waiting for element to be visible, enabled and stable
element is visible, enabled and stable
scrolling into view if needed
done scrolling
performing click action
click action done
waiting for scheduled navigations to finish
navigations have finished

I read discussion about Checkbox and I realized there are difficulties with that too. Is it possible, that Radio Button selection in this case is comparable for those issues?

Hi Kalle,
Have you tried to check (or click) the input tag instead of span?
I don’t have experience of the Check Checkbox keyword, because in my tests this has worked:
Click css:input:not(:checked)[type=‘checkbox’]

As a dirty solution: can you click some element above the radio button, navigate to the radio button by tab and press space to select it?

1 Like

Thanks for tip. I will test it when we will get the environment in case back for our purposes. I will inform you about the result.

Try with js path using execute javascript keyword