Note that there are some explanatory texts on larger screens.

plurals
  1. POHTMLUnit Redirection and Button Click
    primarykey
    data
    text
    <p>I have a problem with HTMLUnit. Shortly what I'm doing is, I'm filling a form and I log-in to a webpage, then I press a button on that page. Actually, I can't do this process, but I'm trying. Here's my HTML form source codes and Java source code: </p> <p>This is from the login screen: </p> <pre><code>&lt;form action="/login" method="post"&gt; ... &lt;input type="text" name="login_email" id="login_email" value="" /&gt; &lt;input type="password" name="login_password" id="login_password" /&gt; &lt;input type="submit" id="login_submit" name="login_submit" value="Sign in" /&gt; &lt;/form&gt; </code></pre> <p>There are some hidden inputs in this form. I know it sounds funny, but my Java code works when I don't do anything about hidden inputs. </p> <p>Here's my Java code for logging in using this form: </p> <p><em><strong>This code is from a stackoverflow question. I'm just testing it, nothing more.</em></strong></p> <pre><code>WebClient webClient = new WebClient(); webClient.setThrowExceptionOnScriptError(false); HtmlPage currentPage = webClient.getPage("https://www.blablabla.com:1234"); final HtmlForm form = currentPage.getFirstByXPath("//form[@action='/login']"); HtmlTextInput username = (HtmlTextInput) currentPage.getElementById("login_email"); HtmlPasswordInput password = (HtmlPasswordInput) currentPage.getElementById("login_password"); username.setText("username@blablabla.com"); password.setText("passW0rd"); HtmlButton submitButton = (HtmlButton) currentPage.createElement("button"); submitButton.setAttribute("type", "submit"); form.appendChild(submitButton); HtmlPage newPage = submitButton.click(); System.out.println(newPage.asText()); </code></pre> <p>Things are good until the next part. I can login, see the contents of the new page. </p> <p>However, when I try to press the button in the new page, I get nothing. Actually, I can't even press it I guess. </p> <p>Here's the HTML source of my "buttony" and new webpage: </p> <pre><code>&lt;form action="auth" method="post"&gt; &lt;input type="submit" name="allow" value="Allow"/&gt; &lt;/form&gt; </code></pre> <p>There are some hidden inputs as well.</p> <p>Here's the Java code for -trying- to press the button with the name 'allow': </p> <pre><code>HtmlButton button = newPage.getElementByName("allow"); HtmlPage page = button.click() ; </code></pre> <p>And to check things for the last time, I use another piece of code: </p> <pre><code>System.out.println(page.asText()); </code></pre> <p>But I get errors like these </p> <p><em><strong>errors start</em></strong> </p> <pre><code>WARNING: getElementById(script1338426904717) did a getElementByName for Internet Explorer 31.May.2012 04:15:04 com.gargoylesoftware.htmlunit.javascript.host.ActiveXObject jsConstructor WARNING: Automation server can't create object for 'ShockwaveFlash.ShockwaveFlash'. 31.May.2012 04:15:04 com.gargoylesoftware.htmlunit.javascript.StrictErrorReporter runtimeError SEVERE: runtimeError: message=[Automation server can't create object for 'ShockwaveFlash.ShockwaveFlash'.] sourceName=[https://www.jdkahsjkda/dksajda.js] line=[12] lineSource=[null] lineOffset=[0] 31.May.2012 04:15:04 com.gargoylesoftware.htmlunit.javascript.host.ActiveXObject jsConstructor </code></pre> <p><em><strong>end of errors</em></strong></p> <p>These errors are OK for me as long as I can login. </p> <p>I can login, and see the page. It says things like "Welcome username password..." But, I can't press the button nor do anything else. </p> <p>I hope you guys can help me with this problem. </p> <p>Thank you very much. </p> <p>Take care, and thank you. </p> <p><em><strong>Edit:</em></strong></p> <p>Now I get this error: </p> <pre><code>Exception in thread "main" com.gargoylesoftware.htmlunit.ElementNotFoundException: elementName=[*] attributeName=[name] attributeValue=[allow] at com.gargoylesoftware.htmlunit.html.HtmlPage.getElementByName(HtmlPage.java:1565) at cza.main(cza.java:54) </code></pre> <p>However, there's a button called 'allow'. I'm looking at the source of the <strong><em>second</em></strong> page, and I see this: </p> <pre><code>&lt;input type="submit" name="allow" value="Allow"/&gt; &lt;input type="submit" name="deny" value="Deny"/&gt; </code></pre> <p>So, there's a button named as allow and deny. However, this code fails. Can this be because of JS or anything? I tried finding the submit button from firstPage and submit the form using it. Not with the fake button, it fails again. I used HTMLSubmitInput for this, it fails again. </p> <p>Thanks again. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload