硒复选框属性"检查" [英] Selenium checkbox attribute "checked"
问题描述
我使用硒在Java中来测试web应用程序复选框的检查。这里的code:
I am using Selenium in Java to test the checking of a checkbox in a webapp. Here's the code:
private boolean isChecked;
private WebElement e;
我宣布电子
并将其分配给那里的复选框的区域。
I declare e
and assign it to the area where the checkbox is.
isChecked = e.findElement(By.tagName("input")).getAttribute("checked").equals("true");
什么是奇怪的是,的getAttribute(选中)
收益空
,因此一个 NullPointerException异常
在HTML的复选框,也不会显示检查
属性。然而,是不是所有的输入
元素有一个检查=真
所以这$ C $的情况下C必须工作?
In the HTML for the checkbox, there is no checked
attribute displayed. However, isn't it the case that all input
elements have a checked = "true"
so this code should work?
推荐答案
如果你正在使用的webdriver那么你正在寻找的是选择的项目。
If you are using Webdriver then the item you are looking for is Selected.
在很多时候呈现的复选框并不实际应用属性检查除非指定。
Often times in the render of the checkbox doesn't actually apply the attribute checked unless specified.
所以,你会寻找在硒的webdriver这是什么
So what you would look for in Selenium Webdriver is this
isChecked = e.findElement(By.tagName("input")).Selected;
由于没有在的webdriver的Java API没有选择的,上面的code应该如下:
As there is no Selected in WebDriver Java API, the above code should be as follows:
isChecked = e.findElement(By.tagName("input")).isSelected;
这篇关于硒复选框属性"检查"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!