【发布时间】:2013-04-13 18:19:55
【问题描述】:
有人请解释为什么会出现空指针异常
HtmlPage page = null;
boolean savePagesLocally = false;
String url = "http://example.com";
WebClient webClient = new WebClient(BrowserVersion.FIREFOX_3_6);
webClient.setThrowExceptionOnScriptError(false);
try
{
page = webClient.getPage( url );
HtmlRadioButtonInput radioButton2 = (HtmlRadioButtonInput) page.getElementById("ctl00_phContent_ucUnifiedSearch_rdoIndvl");
radioButton2.click();
HtmlTextInput textField3 = (HtmlTextInput) page.getElementById("ctl00_phContent_ucUnifiedSearch_txtIndvl");
textField3.setValueAttribute("1061726"); // null pointer occurs here!
【问题讨论】:
-
能贴出html代码吗?这是java代码吗?
-
是htmlscripter生成的java。
-
NPE 的位置意味着没有 id="ctl00_phContent_ucUnifiedSearch_txtIndvl" 的元素
-
@Lee 你是对的。问题是 htmlunit 不等待页面加载。我不得不使用硒来避免这种问题
标签: htmlunit