Htmlunit JavaScript response is not being reflected

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • asrarahmad
    New Member
    • Nov 2012
    • 1

    Htmlunit JavaScript response is not being reflected

    I am trying to to post a comment from a webpage.. Comment web page has textarea and a button type input

    here is html of textarea

    Code:
    <textarea class="aui-field-input aui-field-input-text" id="_33_wgdr_postReplyBody0" name="_33_postReplyBody0" wrap="soft" style="height: 100px; width: 500px;"></textarea>
    and here is the way I am writing some text into textarea

    Code:
    HtmlTextArea hta = (HtmlTextArea) commentPage.getElementsByName("_33_postReplyBody0").get(0);
    hta.setAttribute("value", "This Is Generated Text");
    Button input in html page is

    Code:
      <input class="aui-button-input" onclick="wgdr_postReply(0);" type="button" value="Reply" id="_33_wgdr_postReplyButton0"/>
    I have tried to click on button in either this way

    Code:
     HtmlButtonInput hbi = (HtmlButtonInput) commentPage.getByXPath("//*[@value='Reply' and @type='button']").get(0);
        HtmlPage test = hbi.click();
    or this way

    Code:
      HtmlButtonInput hbi = (HtmlButtonInput) commentPage.getByXPath("//*[@value='Reply' and @type='button']").get(0);
      String functName = hbi.getAttribute("onclick");
      ScriptResult scriptResult = commentPage.executeJavaScript(functName);
    as a result my webpage and thus database should have a new comment "This Is Generated Text" which is not the case at all... I have initialized my webclient in following way:

    Code:
    WebClient webClient = new WebClient(BrowserVersion.INTERNET_EXPLORER_8);
    webClient.setJavaScriptEnabled(true);
        webClient.setThrowExceptionOnScriptError(false);
        webClient.setThrowExceptionOnFailingStatusCode(false);
        webClient.setPrintContentOnFailingStatusCode(false);
        webClient.setTimeout(60000);
        webClient.setJavaScriptTimeout(60000);
        webClient.waitForBackgroundJavaScript(10000);
    I have been digging into this since two days with no fruitful outcomes...Plea se post your thoughts Thanks, -Asrar
    Last edited by zmbd; Nov 15 '12, 06:04 AM. Reason: [Z{Please format posted code using the <CODE/> format button - thnx}]
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    Please post your thoughts
    prime thought, how does the generated HTML/JS code look like?

    btw, I’d be interested where JavaScript comes into play.

    Comment

    Working...