【发布时间】:2019-08-24 00:13:40
【问题描述】:
我想取消选中网页上默认选中的单选按钮,但出现错误
“线程“主”中的异常 org.openqa.selenium.ElementNotVisibleException:元素不是 可交互”
有人可以帮我更正我正在尝试的代码吗?
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>
【问题讨论】:
-
XML 代码是:
-
单选按钮不是复选框:单击它们不会“取消选中”它们。
-
更具体地说,你为什么不直接通过它的 id 获取元素,“traveller”?
-
感谢@RoddyoftheFrozenPeas!我误解了带有复选框的单选按钮,我的代码以前不能使用 Id,但现在我再次尝试,它工作正常。谢谢!
标签: java selenium xpath css-selectors webdriver