复选框已选中,但无法使用硒单击它 [英] Checkbox is Selected but can't able to clicked on it using selenium
本文介绍了复选框已选中,但无法使用硒单击它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
单击复选框后,该复选框突出显示,但未单击 我也没有例外.
On clicking a checkbox, the checkbox is highlighted but its not clicked and i don't get exception .
<input name="include_notice" onclick="javascript:TogglePublishDates();" type="checkbox">
我用名称标识此复选框,并尝试使用sendkeysReturn
和sendKeysEnter
.
I identify this checkbox with Name and tried using sendkeysReturn
and sendKeysEnter
.
注意:此测试用例运行了很长时间,没有对Selenium Web驱动程序或Firefox进行任何更改.
Note: This test case was running good for quite a long time.No changes were made in Selenium Web driver or Firefox.
推荐答案
您可以尝试使用以下代码:
You can try with these below codes:
driver.findElement(By.name("include_notice")).click(); //find checkbox element and click on it.
使用Java脚本执行程序单击复选框.
Click checkbox using java-script executor.
WebElement checkbox = driver.findElement(By.name("include_notice"));
((JavascriptExecutor) driver).executeScript("arguments[0].click();", checkbox);
如果已经选择了复选框,则使用此代码.
If Checkbox is already selected then use this code.
WebElement checkbox = driver.findElement(By.name("include_notice"));
if (!checkBox.isSelected()) //checkbox is not selected then only it will select the checkbox.
{
checkBox.click();
System.out.println(checkbox.isSelected());
}
这篇关于复选框已选中,但无法使用硒单击它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文