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

  • SEARCH
  • Home
  • 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 6593547
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:41:45+00:00 2026-05-25T17:41:45+00:00

I want to write a simple HTMLUnit test script for Jenkins (former Hudson). INFO:

  • 0

I want to write a simple HTMLUnit test script for Jenkins (former Hudson). INFO: Jenkins uses the YUI Javascript library. The YUI library replaces the form submit with a custom button. The script just creates a new job in Jenkins.

start Jenkins:
java -jar jenkins.war

Current versions of HTMLUnit do not support form.submit any more and require you to use button.click() for form submitting. Unfortunately this does not work for Jenkins (the sample below does not advance the page and create the job but stays on the new job page)

I tried for some hours now to find a solution or workaround but so far I could not get the form submitted. Hopefully somebody has found a solution and let me know.

Here is my sample code:

package example;

import com.gargoylesoftware.htmlunit.BrowserVersion;
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.html.HtmlAnchor;
import com.gargoylesoftware.htmlunit.html.HtmlButton;
import com.gargoylesoftware.htmlunit.html.HtmlForm;
import com.gargoylesoftware.htmlunit.html.HtmlInput;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import com.gargoylesoftware.htmlunit.html.HtmlTextInput;
import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput;

public class jenkins3 {
     public static void main(String args[]) {
        // create a new job in jenkins
        // home
        final WebClient webClient = new WebClient(BrowserVersion.FIREFOX_3_6);
        try {
            final HtmlPage page1 = webClient.getPage("http://localhost:8080");
            //assertEquals("Dashboard [Jenkins]", page1.getTitleText());

            // new job
            final HtmlAnchor new_job = page1.getAnchorByText("New Job");
            final HtmlPage page2 = new_job.click();

            // job name
            HtmlTextInput name_field = (HtmlTextInput) page2.getElementById("name");
            name_field.type("new job by htmlunit");

            // radio button
            final HtmlInput radio_freestyle = (HtmlInput) page2.getByXPath("//input[@value='hudson.model.FreeStyleProject']").get(0);
            radio_freestyle.click();
            Thread.sleep(10000);

            // OK button (submit form)
            final HtmlForm form = page2.getFormByName("createItem");
            //final HtmlSubmitInput button = (HtmlSubmitInput) form.getByXPath("//button").get(0);
            final HtmlButton button = (HtmlButton) form.getByXPath("//button").get(0);

            final HtmlPage page3 = button.click(); // !!!!! Form submit does not workstacko
            //assertEquals("Dashboard [Jenkins]", page3.getTitleText());
        }

        catch( Exception e ) {
            System.out.println( "General exception thrown:" + e.getMessage() );
            e.printStackTrace();
        }

        webClient.closeAllWindows();
    }
}
  • 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-05-25T17:41:46+00:00Added an answer on May 25, 2026 at 5:41 pm

    Although this may be completely out of the question in your senerio: i would suggest giving up on HTMLUnit. I’ve had bug after bug, mainly because of the pages I’ve been automating tests for aren’t always 100% valid html (3rd party piggybacked requests). I finally went looking elsewhere and found PhantomJS (js bindings to the WebKit engine) much better suited.
    For me the advantages were evident:
    – no need for another app server
    – much simpler and faster to script JS than Java
    – a “real”-world engine is more realistic than a buggy emulator one
    Thats my advice,
    Cheers

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

Sidebar

Related Questions

I want to write a simple P2P test app which uses HTTP as underlying
I want to write a simple R script using the seewave library. When I
I want to write simple application in C++ using ctime library. I'm getting the
I want to write a simple python script that send a EML file exported
I want to write a simple bash script that will act as a wrapper
I want to write a simple batch script that loads the Visual Studio build
I just want to write a simple text file: ofstream test; test.clear(); test.open(test.txt,ios::out); float
Preface: I am a complete bash noob. I want to write a simple script
Note : question regarding Windows shell I want to write a simple batch script
I want to write a simple chat-client in Ruby for the terminal. The Problem

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.