Tag: htmlunit

Htmlunit:填写自动刷新的表单

我通常可以使用HtmlUnit填写表单并将其提交给服务器。 精细。 不幸的是,我不知道如何根据我在表单上设置的值来填写刷新到服务器的特定表单。 这个表单似乎刷新到服务器,因为在为字段设置值时会触发一些javascript … 举一个简单的例子,我有一个包含2个字段的表单,下拉列表,比如说Country和Region:当我从字段Country选择一个值时,页面自动刷新到服务器(javascript)并显示相同的表单字段区域已更新,可能的值取决于字段Country的先前选择。 这是一个在线测试页面,其中包含我正在讨论的表单: http : //web1.ciemme-service.it/html-unit.nsf/form?OpenForm 我想做的是: – 使用我必须填写的表单加载页面(工作) – 为字段设置值国家(工作) – 等待该页面刷新到服务器(由javascript自动完成… ) – 为字段Region设置一个值 – 提交表单 感谢您提供的任何帮助/提示。

HTMLunit – Facebook登录

final WebClient webClient = new WebClient(); webClient.setJavaScriptEngine(new JavaScriptEngine(webClient)); HtmlPage page1 = null; try { page1 = webClient.getPage(“http://www.facebook.com”); } catch (IOException e) { e.printStackTrace(); } final HtmlForm form = (HtmlForm) page1.getElementById(“login_form”); final HtmlSubmitInput button = (HtmlSubmitInput) form.getInputsByValue(“Log In”).get(0); final HtmlTextInput textField = (HtmlTextInput) page1.getElementById(“email”); textField.setValueAttribute(“test@test.com”); final HtmlPasswordInput textField2 = (HtmlPasswordInput) page1.getElementById(“pass”); textField2.setValueAttribute(“password1”); try { HtmlPage page2 […]

htmlunit中的Cookie策略

如何在htmlunit中指定cookie策略以接受所有cookie?

HtmlUnitexception

我无法理解此HTMLUnitexception的含义。 当我在网页上的链接上调用click()时会发生这种情况。 Exception class=[net.sourceforge.htmlunit.corejs.javascript.WrappedException] com.gargoylesoftware.htmlunit.ScriptException: Wrapped com.gargoylesoftware.htmlunit.ScriptException: TypeError: Cannot read property “offsetWidth” from null (http://webapps6.doc.state.nc.us/opi/scripts/DHTMLmessages.js#95) (javascript url#297) at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:534) at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:537) at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:538) at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.execute(JavaScriptEngine.java:432) at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.execute(JavaScriptEngine.java:407) at com.gargoylesoftware.htmlunit.html.HtmlPage.executeJavaScriptIfPossible(HtmlPage.java:965) at com.gargoylesoftware.htmlunit.html.HtmlAnchor.doClickAction(HtmlAnchor.java:87) at com.gargoylesoftware.htmlunit.html.HtmlAnchor.doClickAction(HtmlAnchor.java:121) at com.gargoylesoftware.htmlunit.html.HtmlElement.click(HtmlElement.java:1329) at com.gargoylesoftware.htmlunit.html.HtmlElement.click(HtmlElement.java:1288) at com.gargoylesoftware.htmlunit.html.HtmlElement.click(HtmlElement.java:1257) at testapp.TestApp.main(TestApp.java:61) Caused by: net.sourceforge.htmlunit.corejs.javascript.WrappedException: Wrapped com.gargoylesoftware.htmlunit.ScriptException: TypeError: Cannot read property “offsetWidth” from null (http://webapps6.doc.state.nc.us.js#95) (javascript […]

HtmlUnit无法获取IFRAME添加的js / ajax

我刚开始通过gargoylesoftware学习htmlunit ,我遇到了问题。 页面上有一个iframe,单击按钮后会出现。 当我尝试按名称获取此iframe时,我得到一个ElementNotFoundException 。 此外,我尝试了page.getFrames() ,它返回帧,但没有我正在寻找的帧或它是空白的。 所以看起来js / ajax没有更新它。 我在jcpenny(dot)com上工作,当我尝试从“My Bag”页面“checkout”时出现问题这是我的WebClient设置 BrowserVersion bv = BrowserVersion.CHROME_16; bv.setUserAgent(“Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)”); CookieManager cm = new CookieManager(); cm.clearCookies(); cm.setCookiesEnabled(true); WebClient webClient = new WebClient(bv); webClient.setCookieManager(cm); webClient.setAjaxController(new NicelyResynchronizingAjaxController()); webClient.setJavaScriptTimeout(15000); webClient.setCssErrorHandler(new SilentCssErrorHandler()); webClient.getOptions().setJavaScriptEnabled(true); webClient.getOptions().setThrowExceptionOnScriptError(false); webClient.waitForBackgroundJavaScript(15000); webClient.getOptions().setThrowExceptionOnFailingStatusCode(false); webClient.getOptions().setRedirectEnabled(true); webClient.getOptions().setUseInsecureSSL(true); webClient.setRefreshHandler(new ThreadedRefreshHandler());

是否可以在HTMLunit中使用HTTPS代理?

我是HTMLunit的新手,并尝试为HTMLunit设置HTTPS代理。 我试图在HOST IP之前使用https://但是我得到了Exception。 有人可以帮我解决这个问题吗? 更新:我的代码是: WebClient webClient = new WebClient(BrowserVersion.FIREFOX_3_6,”https://199.127.100.13″, 11888); 更新2:我问开发团队,The说这是框架中的一个bug。 他们会解决它。

HTMLUNIT getformbyname,网站中未指定表单名称

我正在尝试使用HTMLUNIT来浏览网站上的按钮我遵循本教程http://htmlunit.sourceforge.net/gettingStarted.html但它需要一个表单名称。 我正在尝试做的网站有这个页面来源。 Are you sure you want to delete ‘Apple?’? 我正在尝试单击网页上的“是”按钮validation框。(删除按钮)如您所见,没有提供表单名称。 这是我的代码。 final WebClient webClient = new WebClient(); final HtmlPage page1 = webClient.getPage(“http://ma.some-site.com:8080/user/mike/delete”); List formlist = (List) page1.getForms(); System.out.println(formlist.toString()); final HtmlForm form = page1.getFormByName(“myform”); <—Problem here final HtmlSubmitInput button = form.getInputByName("Submit"); button.click(); webClient.closeAllWindows(); 我尝试了这个但是没有用 final HtmlForm form = page1.getFormByName(formlist.get(1).getLocalName()); 我相信你可以使用xpath来查找表单名称?

如何忽略与jQuery相关的HTMLUnit警告/错误?

是否有可能教HTMLUnit忽略网页上的某些 JavaScript脚本/文件? 其中一些只是我的控制(如jQuery),我不能对它们做任何事情。 警告很烦人,例如: [WARN] com.gargoylesoftware.htmlunit.javascript.host.html.HTMLDocument: getElementById(script1299254732492) did a getElementByName for Internet Explorer 实际上我正在使用JSFUnit,HTMLUnit在它下面工作。

HtmlUnit下载文件

我试图通过HTMLUnit下载文件。 但每当我使用这样的代码时: InputStream stream = anchor.click().getWebResponse().getContentAsStream(); 我得到网站而不是文件。 下载链接如下所示: 有没有办法下载这个?

错误E:使用HtmlUnit执行javascript

我正在尝试在以下url上执行javascript: http://steamcommunity.com/id/bobcatchris/inventory#730 : http://steamcommunity.com/id/bobcatchris/inventory#730 。 我可以通过按ctrl + shift + j并粘贴以下脚本打开控制台,使用谷歌浏览器: var list = []; var size = Object.keys(g_ActiveInventory.rgInventory).size(); var counter = 0; while (counter < size) { list.push(g_ActiveInventory.rgInventory[Object.keys(g_ActiveInventory.rgInventory)[counter]].market_name); counter +=1; } 它返回:150然后在下一行,我写: >list ,它返回一个长度为150的数组。 当我尝试在HtmlUnit执行此操作时: public static void main(String[] args) throws IOException { WebClient webClient=new WebClient(BrowserVersion.FIREFOX_17); HtmlPage page=webClient.getPage(“http://steamcommunity.com/id/bobcatchris/inventory#730″); String script=”var list = [];\n” + “\n” […]