JavaScript not being properly executed in HtmlUnit

后端 未结 1 1980
清歌不尽
清歌不尽 2020-12-11 23:55

I\'m currently developing some tests with HtmlUnit. It\'s loading a page that contains braintree.js (their form encryption library). I have a bunch running, but I\'m stuck

相关标签:
1条回答
  • 2020-12-12 00:29

    Based on your comment, I have to tell you that HtmlUnit is a pain in the neck when it comes to JavaScript. It will complain a lot about variables not being defined and unknown functions and so on.

    Real browsers are more flexible, eg: they accept syntactically incorrect pieces of JavaScript. HtmlUnit expects everything to be perfect without any kind of error. Furthermore, even if you didn't miss a semicolon, HtmlUnit might complain.

    My advice:

    • Make sure your JavaScript is syntactically correct
    • Avoid the user of complex libraries (jQuery seems to be properly supported)
    • If you can use non-minimized versions of libraries it's worth giving it a try
    • Try to avoid complex jQuery methods (eg: adding events dynamically to elements)
    • And the most important one: Try switching between different BrowserVersions. Internet Explorer (ironically) has proven to provide the best results when it comes to interpreting JavaScript
    0 讨论(0)
提交回复
热议问题