httpUnit无法获取select框的选项值(options)

今天用httpunit写一个测试时候发现无法设置select框,报错是:
com.meterware.httpunit.IllegalParameterValueException: May not set parameter ‘userInfo.processingUnit’ to ‘BOM’. Value must be one of: { }
at com.meterware.httpunit.SelectionFormControl$Options.reportNoMatches(FormControl.java:1186)
at com.meterware.httpunit.SelectionFormControl$SingleSelectOptions.claimUniqueValues(FormControl.java:1360)
at com.meterware.httpunit.SelectionFormControl$Options.claimUniqueValues(FormControl.java:1178)
at com.meterware.httpunit.SelectionFormControl.claimUniqueValue(FormControl.java:1059)

跟进发现,webform无法通过getOptions来获取选择项.google后发现有人建议把页面中的

<html xmlns=”http://www.w3.org/1999/xhtml”>
改成
<html>

果然管用. 为什么会影响到httpunit? 指定上述的命名空间的意思是说这个html文档是遵守xhtml规范.通过下面的方法打开httpunit的解析详情 – httpunit会在得到html内容后告诉你这个文档是否遵守了你所指定的规范.(这里是xhtml).

HttpUnitOptions.setParserWarningsEnabled(true);

结果会得到这样的信息:
At line 121, column 1: Element <BODY> not closed properly.
At line 121, column 1: Element <HTML> not closed properly.
At line 1249, column 1: Element <BODY> not closed properly.
At line 1249, column 1: Element <HTML> not closed properly.
At line 1477, column 1: Element <BODY> not closed properly.
At line 1477, column 1: Element <HTML> not closed properly.

也就是输出的页面已经不是严格遵守xhtml的了.(推测是sitemesh的使用问题,没有很好的组织页面之间的关系依赖.),然后HttpUnit使用他的html解析器去查找select框的options时就出问题了. 为什么httpunit的作者不把具体原因给出来呢?

Comments are closed.