外部网站上有两个HtmlSelects。
第一个("句号")有静态属性。但是第二个(" date")处于禁用状态,并且在加载页面时没有选项。 (" date")字段被启用,并且在选择(" period")时填充数据。 通过HTMLUnit执行时,此功能不起作用。
下面提到的是我的代码
WebClient webClient = new WebClient();
webClient.getOptions().setJavaScriptEnabled(true);
webClient.getOptions().setThrowExceptionOnScriptError(false);
webClient.getOptions().setCssEnabled(false);
webClient.setAjaxController(new NicelyResynchronizingAjaxController());
HtmlPage page = webClient.getPage(PAGE_URL);
HtmlSelect select = (HtmlSelect) page.getElementById("period");
HtmlOption option = select.getOptionByText("Q1");
select.setSelectedAttribute(option, true); select.fireEvent(Event.TYPE_CHANGE);
Thread.sleep(20000);
HtmlSelect select1 = (HtmlSelect) page.getElementById("date");
HtmlOption option1 = select1.getOptionByValue("2"); //EXCEPTION IN THIS LINE
select1.setSelectedAttribute(option1, true);
以下是捕获的异常
com.gargoylesoftware.htmlunit.ElementNotFoundException: elementName=[option] attributeName=[value] attributeValue=[2]
at com.gargoylesoftware.htmlunit.html.HtmlSelect.getOptionByValue(HtmlSelect.java:437)
似乎(" date")字段未启用并填充。
非常感谢任何帮助。 提前谢谢!
答案 0 :(得分:0)
Without more details it is really tricky to give some advice.
Please report:
Hope that helps, if you need more support provide a complete reproducible sample.
Regarding your version: version 2.13 is really outdated and of course we did many fixes for event handling/processing and also for the select control. Please use the latest version - this is the only version we can support because the development team is really small.