猿问

用htmlunit拿到的htmlImage元素,调用click事件不能触发元素的onclick事件

String url = "xx.jsp";
WebClient wc = new WebClient(BrowserVersion.CHROME);
wc.getCookieManager().setCookiesEnabled(true);
wc.setAjaxController(new NicelyResynchronizingAjaxController());

WebRequest request = new WebRequest(new URL(url));

WebResponse response = wc.loadWebResponse(request);
System.out.println(response.getContentAsString());

// HtmlPage page = HTMLUnitUtil.getHTMLPageByURL(wc, url, false);
//
//// // 获取页面元素
// HtmlForm form = page.getForms().get(0);
//
// HtmlInput company = form.getInputByName("companyCode");
// company.setValueAttribute("xx");
//
// HtmlInput userID = form.getInputByName("userID");
// userID.setValueAttribute("xx");
//
// HtmlImage goImg = form.getOneHtmlElementByAttribute("img", "name", "goImg");
//
// Page temp = goImg.click();

拿到的temp还是之前的page内容


明月笑刀无情
浏览 1606回答 1
1回答

Helenr

直接触发JS function吧
随时随地看视频慕课网APP
我要回答