On my automation tests, I am struggling to click a radio button. Even though the radio buttons are visible on the page, the unselected ones have the property displayed:false
. Selenide seems unable to click if an html object has the displayed:false
property. The error message received is:
Element should be visible {By.id: radio_btn_id}
Here is the radio button in question:
<input class="radio_class" id="radio_btn_id" name="radio_btn_name" type="radio" value="12" displayed:false></input>
I've attempted to remove this property using various methods, but none of them seem to work:
SelenideElement element = $(By.id(id));
Selenide.executeJavaScript("document.getElementById('radio_btn_id').removeAttribute('displayed:false')", element);
Selenide.executeJavaScript("document.getElementById('radio_btn_id').removeAttribute(\"displayed:false\")", element);
Selenide.executeJavaScript("jQuery('select:not(:visible)').css('display','block')", element);
Oddly enough, removing the selected:true
property did work. I'm not sure why it's unsuccessful for displayed:false
. Any ideas?
[EDIT]
The accepted answer involves using Selenium
version. However, with Selenide
it can be achieved more cleanly and simply:
SelenideElement element = $(By.id(id));
Selenide.executeJavaScript("document.getElementById('"+ id+ "').click();", element);
[SOLUTION]
Check out this resource on how Selenide behaves with checkboxes and radio buttons.