简体   繁体   English

Click()函数不起作用HtmlUnit

[英]Click() Function Not Working HtmlUnit

Hey I'm having some trouble clicking a button to submit a comment on a thread using htmlUnit. 嘿,我在单击按钮以使用htmlUnit在线程上提交评论时遇到了一些麻烦。 I get the element by using this 我通过使用此元素

HtmlPage newOne = webClient.getPage(string);
//System.out.println(newOne.asText());
HtmlTextArea area = (HtmlTextArea) newOne.getElementById("ctrl_message_html");
area.focus();
area.type('t');

newOne.getHtmlElementByAccessKey('s').click();

Which throws 哪个抛出

com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException: 404 Not Found for http://forums.bukkit.org/threads/plugin-idea-to-get-tons-of-downloads.271185/members/jthort.90885864/post
at com.gargoylesoftware.htmlunit.WebClient.throwFailingHttpStatusCodeExceptionIfNecessary(WebClient.java:514)
at com.gargoylesoftware.htmlunit.WebClient.loadDownloadedResponses(WebClient.java:2067)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.doProcessPostponedActions(JavaScriptEngine.java:717)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.processPostponedActions(JavaScriptEngine.java:804)
at com.gargoylesoftware.htmlunit.html.HtmlElement.click(HtmlElement.java:1322)
at com.gargoylesoftware.htmlunit.html.HtmlElement.click(HtmlElement.java:1265)
at com.gargoylesoftware.htmlunit.html.HtmlElement.click(HtmlElement.java:1213)
at HTMLUnit.main(HTMLUnit.java:87)

When I print out the element, I get this 当我打印出元素时,我得到了

HtmlSubmitInput[<input type="submit" class="button primary MenuCloser" value="Post" accesskey="s">]

But I don't understand why it would be throwing an exception when it clearly has the right object. 但是我不明白为什么当它显然具有正确的对象时会引发异常。 I have javascript disabled, along with css. 我禁用了JavaScript,以及CSS。 I am using the web browser Chrome. 我正在使用网络浏览器Chrome。

Edit: By right Object I mean that it's the correct button on the page that I want to click and it's in the form of a HtmlSubmitInput button. 编辑:通过正确的对象,我的意思是这是我要单击的页面上的正确按钮,并且采用HtmlSubmitInput按钮的形式。

I'm not sure why you think having the right object will mean you won't get any exception. 我不确定为什么您认为拥有正确的对象将意味着您不会获得任何例外。 You're not getting a NullPointerException , if that is what you mean by the right object . 如果那是正确对象的意思,则您没有得到NullPointerException

Having said that, if you read the exception it is a FailingHttpStatusCodeException with the following message: 话虽如此,如果您阅读该异常,则它是一个FailingHttpStatusCodeException带有以下消息:

404 Not Found for http://forums.bukkit.org/threads/plugin-idea-to-get-tons-of-downloads.271185/members/jthort.90885864/post 未找到http://forums.bukkit.org/threads/plugin-idea-to-get-tons-of-downloads.271185/members/jthort.90885864/post的 404

So that URL is giving you a 404 error when you perform an HTTP POST on it. 因此,当您对它执行HTTP POST时,该URL会给您404错误。 You should keep debugging why this is happening. 您应该继续调试为什么会这样。 I would enable JavaScript, maybe it is needed there. 我将启用JavaScript,也许在那里需要。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM