0

I want to uncheck the radio button on a webpage which is checked by default but i am getting error

"Exception in thread "main" org.openqa.selenium.ElementNotVisibleException: element not interactable"

Can someone please help me to correct my code which i am trying?

WebElement travellerbutton = driver.findElement(By.xpath("//label[text()='Traveller']/preceding-sibling::input[@type='radio']"));
travellerbutton.click();

HTML:

<div class="radio">
    <input type="radio" name="tgselect" id="traveller" checked="">
    <label for="traveller">Traveller</label>
    <div class="check"></div>
</div>
DebanjanB
  • 118,661
  • 30
  • 168
  • 217

2 Answers2

0

Probably, there are several radio buttons and you need to select another one. But in case, you can uncheck radio button using JavaScript, try code below:

((JavascriptExecutor)driver).executeScript("arguments[0].checked=false;", driver.findElement(By.id("traveller")));
Sers
  • 10,960
  • 2
  • 8
  • 25
0

To click() on the element associated with the <label> with text as Traveller you can use either of the following Locator Strategies:

  • cssSelector:

    driver.findElement(By.cssSelector("label[for='Traveller']")).click();
    
  • xpath:

    driver.findElement(By.xpath("//label[@for='Traveller']")).click();
    
DebanjanB
  • 118,661
  • 30
  • 168
  • 217