如何在javascript完成后让HtmlUnit更新页面

时间:2015-10-15 15:30:31

标签: javascript java html htmlunit

我正在尝试加载在触发侦听器时更改的div的内容。

我目前拥有的java代码是:

test.html

和我的<html> <head> <script type="text/javascript" src="https://www.google.com/jsapi"></script> <script type="text/javascript"> google.load("visualization", '1', {packages:['corechart']}); google.setOnLoadCallback(drawChart); function drawChart() { // var query = new google.visualization.Query('simpleexample?tq=select name,population'); // query.send(handleSimpleDsResponse); handleSimpleDsResponse(true); function handleSimpleDsResponse(response) { // var data = response.getDataTable(); var data = google.visualization.arrayToDataTable([ ['Year', 'Sales', 'Expenses'], ['2013', 1000, 400], ['2014', 1170, 460], ['2015', 660, 1120], ['2016', 1030, 540] ]); var chart_div = document.getElementById('chart_div'); var chart_data = document.getElementById('chart_data'); var test = document.getElementById('test'); var chart = new google.visualization.AreaChart(chart_div); // Wait for the chart to finish drawing before calling the getImageURI() method. google.visualization.events.addListener(chart, 'ready', function () { chart_div.innerHTML = '<img src="' + chart.getImageURI() + '">'; chart_data.innerHTML = chart.getImageURI(); test.innerHTML = "after"; }); chart.draw(data); } } </script> </head> <body> <div id="test">before</div> <div id='chart_div'></div> <div id="chart_data"></div> </body> </html> 页面(加载谷歌图表)是:

before

但是当我打印div时,它总是等于after而不是{{1}}。如何在图表加载完成后获取值?

1 个答案:

答案 0 :(得分:0)

这是处理Promise.resolve()的错误,已在SVN修复。

请使用new WebClient(BrowserVersion.CHROME)latest build或快照。

不需要wait(),因为它不是基于AJAX的。