title: How can i execute my javascript function inside my jsp page
body: <p>I have written my javascript function inside my JSP and i want to execute that function  using webclient.  Is there is any way for doing this?</p>
  
  <pre><code>package com.test.app;
  
  import com.gargoylesoftware.htmlunit.BrowserVersion;
  import com.gargoylesoftware.htmlunit.WebClient;
  import com.gargoylesoftware.htmlunit.html.HtmlPage;
  
  public class FinalTest {
    public static void main(String[] args) throws Exception {
  
      WebClient webClient = new WebClient(BrowserVersion.CHROME);
  
      HtmlPage page = webClient.getPage("http://jbosstest/WebPage/Home.jsp?code=GIL&amp;appStatus=R&amp;AppRemarks=Finally");
  
      String javaScriptCode =  "funcCPDiv('Insert')";
  
      Object result = page.executeJavaScript(javaScriptCode).getJavaScriptResult();
      System.out.println(result);
    }
  }
  </code></pre>
  
  <p>Below is the error which I am getting while running my code  </p>
  
  <pre><code>    Exception in thread "main" java.lang.ClassCastException:
      com.gargoylesoftware.htmlunit.TextPage cannot be cast to
      com.gargoylesoftware.htmlunit.html.HtmlPage
      com.test.app.FinalTest.main(FinalTest.java:11)
  </code></pre>
  
  <p>Someone told me to use <code>HTMLUnit</code> but I am not able to understand how can I use it with a my simple example which I have mentioned above. I have tried with connection url of Java but it is not executing my javascript function it is just returning me HTML content.</p>