Results 1 to 2 of 2
  1. #1
    MohseN16 is offline Member
    Join Date
    Oct 2012
    Posts
    6
    Rep Power
    0

    Default HtmlUnit returns the same page

    When I try to submit a form of a page , It will return the same page , I think that there is something interrupting so the server rejects the request.

    Any solution?

    These codes will be run after the button has been clicked:


    Java Code:
    WebClient wc; 
    HtmlPage page;
        wc = new WebClient(BrowserVersion.INTERNET_EXPLORER_11);
    
        try {
            page = wc.getPage("http://srv3.sanjesh.org/p_krn/index.php/krn_res_sar93r1/sar_93rmz/krn");
        } catch (FailingHttpStatusCodeException | IOException e2) {
            // TODO Auto-generated catch block
            e2.printStackTrace();
        } 
            try {
    
    
    
                    wc.getOptions().setJavaScriptEnabled(true);
                    wc.getOptions().setCssEnabled(true);
                    wc.getOptions().setRedirectEnabled(true);
                    wc.setAjaxController(new NicelyResynchronizingAjaxController());
                    wc.getCookieManager().setCookiesEnabled(true);
    
                    wc.getOptions().setActiveXNative(true);
                    wc.getOptions().setGeolocationEnabled(true);
                    wc.getOptions().setAppletEnabled(true);
                    wc.getOptions().setPrintContentOnFailingStatusCode(true);
    
    
                    page.getWebClient().addRequestHeader("Content-Type","text/html; charset=utf-8");                
    
                    //filling required data
                    HtmlElement shomaredav = page.getElementByName("num_d");
                    HtmlElement namekhan = page.getElementByName("name_l");
                    HtmlElement nam = page.getElementByName("name_s");
                    HtmlElement saletaval = page.getElementByName("saltvl");
                    List<DomElement> shomareshenases = page.getElementsByName("id_number");
                    List<DomElement> captchas = page.getElementsByName("captcha");
                    List<DomElement> submits = page.getElementsByName("submit2");
                    HtmlElement captcha = (HtmlElement) captchas.get(1);
                    HtmlElement shomareshenas = (HtmlElement) shomareshenases.get(1);
                    HtmlElement submit = (HtmlElement) submits.get(1);
    
                    shomaredav.click();
                    shomaredav.type("some secret data");
                    namekhan.click();
    
                    namekhan.type("Some secret data");
                    nam.click();
                    nam.type("some secret data");
                    saletaval.click();
                    saletaval.type("74");
                    captcha.click();
                    captcha.type(textField_2.getText());
                    shomareshenas.click();
                    shomareshenas.type("some secret data");
    
                    HtmlPage page2 = submit.click();
                       System.out.println(page.getWebResponse().getStatusMessage());
    
                    page2.save(new File("D:\\test.html"));
    
                } catch (FailingHttpStatusCodeException | IOException e1) {
                    // TODO Auto-generated catch block
                    e1.printStackTrace();
                }

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    26

    Default Re: HtmlUnit returns the same page

    Debug it?
    There's not much there that we can go on.

    Have you looked into exactly what's went to the server?
    Have you looked at the response?
    Fiddler would be handy here.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. Replies: 13
    Last Post: 07-10-2014, 04:28 PM
  2. i cannot give this page with htmlunit
    By ansar313 in forum New To Java
    Replies: 11
    Last Post: 05-20-2011, 09:38 PM
  3. using of htmlunit library
    By ahmad_javadi in forum Advanced Java
    Replies: 2
    Last Post: 07-26-2010, 12:43 PM
  4. using of htmlunit library
    By ahmad_javadi in forum New To Java
    Replies: 0
    Last Post: 07-26-2010, 12:32 PM
  5. use of pressAccessKey in htmlunit
    By ahmad_javadi in forum New To Java
    Replies: 1
    Last Post: 07-21-2010, 02:22 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •