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>
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Swati Mittal
  • 29
  • 1
  • 6

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
  • 12,047
  • 2
  • 12
  • 31
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();
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352