From: Alexandru M. <ale...@gm...> - 2021-06-26 15:44:01
|
<html><head></head><body><div style="font-family: Verdana;font-size: 12.0px;"><div>Good day,</div> <div> </div> <div> </div> <div>I have used HtmlUnit to open a web page from Java, and then call a Javascript function which returns a Promise. I am able to get a handle to the returned Promise (htmlunit.javascript.host.Promise) which has a .then(onFulfilled: Function, onRejected: Function) method (htmlunit.corejs.javascript.Function). But creating such a Function requires many methods to be implemented, and i am not sure if this is the way to go.</div> <div> </div> <div> </div> <div> <pre>val page = webClient.getPage("...").asInstanceOf[HtmlPage]</pre> <div> <pre>val res = page.executeJavaScript("myFunction(...)").getJavaScriptResult.asInstanceOf[Promise]</pre> <div>res.then(...)</div> <div> </div> <div> </div> <div>I have also looked through HtmlUnit tests and it seems there the Promise tests are using a DOM element on the page to which the result is written. I wanted to see if there is a way for Java to use the Promise result without the intermediary DOM node.</div> <div> </div> <div> </div> <div>Thank you,</div> <div>Alex</div> </div> </div></div></body></html> |