Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8043755
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T05:00:41+00:00 2026-06-05T05:00:41+00:00

I have a problem with HTMLUnit. Shortly what I’m doing is, I’m filling a

  • 0

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:

This is from the login screen:

<form action="/login" method="post"> 
 ...
 <input type="text" name="login_email" id="login_email" value="" />
 <input type="password" name="login_password" id="login_password" />
 <input type="submit" id="login_submit" name="login_submit" value="Sign in" />
</form>

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.

Here’s my Java code for logging in using this form:

This code is from a stackoverflow question. I’m just testing it, nothing more.

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()); 

Things are good until the next part. I can login, see the contents of the new page.

However, when I try to press the button in the new page, I get nothing. Actually, I can’t even press it I guess.

Here’s the HTML source of my “buttony” and new webpage:

<form action="auth" method="post">
 <input type="submit" name="allow" value="Allow"/>
</form>

There are some hidden inputs as well.

Here’s the Java code for -trying- to press the button with the name ‘allow’:

HtmlButton button = newPage.getElementByName("allow");
HtmlPage page = button.click() ;

And to check things for the last time, I use another piece of code:

System.out.println(page.asText());

But I get errors like these

errors start

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

end of errors

These errors are OK for me as long as I can login.

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.

I hope you guys can help me with this problem.

Thank you very much.

Take care, and thank you.

Edit:

Now I get this error:

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)

However, there’s a button called ‘allow’. I’m looking at the source of the second page, and I see this:

<input type="submit" name="allow" value="Allow"/>
<input type="submit" name="deny" value="Deny"/>

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.

Thanks again.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T05:00:43+00:00Added an answer on June 5, 2026 at 5:00 am

    Sorry I can’t comment yet…

    What’s the newPage.getWebResponse().getContentAsString() content ?
    I guess your page may contains many html elements with name “allow”

    It’s best to be sure that you get an unique and right element, there’s many ways to do it :

    element.getElementById("id")
    page.getFirstByXPath("xpathExpr") || page.getByXPath("xpathExpr")
    

    and so on … the goal is really to be sure to use the element you need.

    When playing with inputs, it’s always a good way to get as variable the form to manipulate the inputs. eg :

    HtmlForm form = page.getforms(0); 
    form.getInputByName("name");
    form.getInputByValue("value");
    

    BTW, some tips : initialize the webclient with FF settings like this :
    client = new WebClient(BrowserVersion.FIREFOX_3_6);
    it got the best html code coverage ( http://build.canoo.com/htmlunit/artifacts/ )

    always try with JS on/off : client.setJavaScriptEnabled(false);client.setThrowExceptionOnScriptError(false);

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have problem with Uploadify: I log in the project using: FormsAuthentication.SetAuthCookie(myName, false); Then,
I have a simple HTML page (ratings.html) that I'm trying to test using HtmlUnit.
I am using HtmlUnit in some programs and I always have the problem that
I have opened a webpage in HtmlUnit headless browser. Now that webpage contains a
I have problem with Visual Studio Designer. When I display design of a form,
I have problem with filling a Map in Java, I think this is simple,
I have problem witch change style border-left-color in next button, if main button is
I have problem with customizing each page using pagecontrol and UIScrollView. I'm customizing Page
I have problem calling a JavaScript function in an iframe from the parent page.
I have problem with my code. I don't know what am I doing wrong.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.