Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/369.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java htmlunit:未选中复选框_Java_Html_Htmlunit - Fatal编程技术网

Java htmlunit:未选中复选框

Java htmlunit:未选中复选框,java,html,htmlunit,Java,Html,Htmlunit,我正在使用HtmlUnit设置页面中的复选框。复选框的Html代码为: <input id="Checkbox" type="checkbox" name="Checkbox" style="color:Black;"/> HtmlCheckBoxInput checkBox = page.getHtmlElementById("Checkbox"); checkBox.setCh

我正在使用HtmlUnit设置页面中的复选框。复选框的Html代码为:

<input id="Checkbox" type="checkbox"  name="Checkbox" style="color:Black;"/>
HtmlCheckBoxInput checkBox = page.getHtmlElementById("Checkbox");
checkBox.setChecked(true);
        
FileUtils.writeStringToFile(new File("src/test/page-dumps/page-3.html"),page.asXml(),"UTF-8");

当我在浏览中打开
page-3.html
时,ckeckbox未选中。为什么它没有被选中?

你能试着将
选中的
属性添加到
元素中吗?

好吧,它没有被选中,因为真正的浏览器没有添加属性

使用real browser测试以下各项:


功能测试(){
var e=document.getElementById('myid');
e、 选中=正确;
警报(如outerHTML);
}
有一个警报


未选中任何
属性

您应改为使用:

checkBox.setAttribute("checked", "checked");