title: Send event to JavaFx webview node/element from Java code
body: <p>I need to automatically execute a repetitive operation on the webbrowser.
  For that I need to do stuff like send clicks and other input to the webpage from java code.</p>
  
  <pre><code>Element e = document.getElementById("someid");
  com.sun.webpane.webkit.dom.MouseEventImpl.MouseEventImpl mei = MouseImplExpose.makeSimpleClickDummy(e);
  ((EventTarget)e).dispatchEvent(mei);
  </code></pre>
  
  <p>Where MouseImplExpose is</p>
  
  <pre><code>package com.sun.webpane.webkit.dom;
  
  import org.w3c.dom.Document;
  import org.w3c.dom.Node;
  
  public class MouseImplExpose {
      public static MouseEventImpl makeDummy(Node n){
         // required jdk 7 update 40 ! This function is
          // not available in jdk 7 update 10 :O
          return new MouseEventImpl(((NodeImpl)n).peer );
      }
  
      public static MouseEventImpl makeSimpleClickDummy(Node n/*, Document d*/){
          //d.getD
  
          MouseEventImpl impl = new MouseEventImpl(((NodeImpl)n).peer );
          // some fictional values
          impl.initMouseEvent(
                  "click", 
                  true, 
                  true, 
  
                  null, 
                  1, 
                  958, 
                  318, 
                  718, 
                  208, 
                  false, 
                  false, 
                  false, 
                  false, 
                  (short)0, 
                  (NodeImpl)n);
          return impl;
          // this is how a real MouseEventImpl generated 
          // internally looks :
          /*evt=com.sun.webpane.webkit.dom.MouseEventImpl@ad3b429
          typeArg=click
          canBubbleArg=true
          cancelableArg=true
          viewArg=[object DOMWindow]
          detailArg=1
          screenXArg=958
          screenYArg=318
          clientXArg=718
          clientYArg=208
          ctrlKeyArg=false
          altKeyArg=false
          shiftKeyArg=false
          metaKeyArg=false
          buttonArg=0
          relatedTargetArg=[object HTMLDivElement]*/
      }
  }
  </code></pre>
  
  <p>I am getting a org.w3c.dom.events.EventException from native side.</p>
  
  <p>I am sure there must be a simpler way to do it .... </p>
  
  <p>Any tip, hint, guide, link, comment would be highly appreciated.
  Thanks</p>
  
  <hr>
  
  <p>I found this alternate approach works</p>
  
  <pre><code>System.out.println(webEngine.executeScript("var evt = document.createEvent(\"MouseEvents\");\n"+
  "                evt.initMouseEvent(\"click\", true, true, window, 1, 0, 0, 0, 0,\n" +
  "                    false, false, false, false, 0, null);\n" +
  "\n" +
  "                var cb = document.getElementById(\"TheIdOfElementWeWishToClick\");\n" +
  "                cb.dispatchEvent(evt);"
  + "%"));
  </code></pre>
  
  <p>Earlier I was trying </p>
  
  <pre><code>System.out.println(webEngine.executeScript("document.getElementById(\"TheIdOfElementWeWishToClick\").click();");
  </code></pre>
  
  <p>Which didn't work as ".click()" does not work on .</p>