Is there a way to trigger scroll event with HtmlUnit or is it not possible at all?
i would suggest u use casperjs instead of htmlunit in this situation, i tried use htmlunit to open pinterest and got
runtimeError: message=[Property 0 not found.] sourceName=[https://s.pinimg.com/webapp/js/vendor-react-d20f99c48b5d58e4821c.js] line=[1] lineSource=[null] lineOffset=[0]
so it does look htmlunit don't have a good support for js, even the latest version 2.31..
here is a demo code using casperjs:
var utils = require('utils')var fs = require('fs')var system = require('system')var casper = require('casper').create({ verbose: true, logLevel: 'debug', localToRemoteUrlAccessEnabled: true, webSecurityEnabled: false, plainTextAllContent: false, viewportSize: { width: 1440, height: 800 }, onError: function(casper, msg, backtrace) { utils.dump(backtrace) }});var cookie = fs.read('cookie.txt').trim() casper.on('started', function() { this.page.onError = function(msg, trace) { casper.echo('Error => ' + msg + '\nError trace => ') utils.dump(trace) } this.page.customHeaders = { "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.139 Safari/537.36", "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", "Accept-Language": "zh-CN,en;q=0.5", "Accept-Encoding": "gzip, deflate", "Connection": "keep-alive", "Pragma": "no-cache", "Cookie": cookie }});casper.start('https://www.pinterest.com', function() { this.then(function() { this.waitForSelector('div[class="_wx _2h"]', function() { this.echo("waitForSelector 'div[class=_wx _2h]' is done") this.scrollTo(0, 1000); this.wait(5000, function() { this.scrollTo(0, 2000); }) }) })});
save above code to a file say named demo.js, then use following command to start casperjs
casperjs --engine=slimerjs demo.js
then u will see the firefox browser startup visually and working!