0

Is it possible to deselect a radio button using Selenium?

If you don't know what selenium is visit the site here: Selenium

I tried double clicking on the radio button using Selenium but that doesn't work:

WebElement select = driver.findElement(By.xpath("//td[1]/input[1]"));
select.click();
select.click();

Using selenium to reload the page does not work as the checked attribute is present in the radio tag.

developer234
  • 79
  • 3
  • 14

2 Answers2

0

A radiobutton is usually part of a set. This configuration forces users to make a choice, it means that one of the buttons in the set MUST be checked and ONLY ONE can be checked. You can not uncheck the button because this would imply that no button in the set is checked. If you want a specific button to be unchecked, you need to check another button in the set: this will automatically uncheck the button you wanted unchecked.

Steve
  • 367
  • 3
  • 11
0

I have executed JavaScript on the page to accomplish this before:

const radioButton = document.querySelector(selector)
radioButton.checked = false

But I've also refactored my tests to skip ever clicking the radio button in the first place.

Ian Walter
  • 882
  • 2
  • 8
  • 23