我讀過這phantomjs not waiting for "full" page load但它並沒有解決我的問題。PhantomJS和CasperJS不加載JS
我已經試過這(我的HTML,而不是整個):
<div id="test"></div>
<script>
window.onload = function() {
document.getElementById('test').innerHTML = 'something';
console.log('page loaded');
};
</script>
而這在我的JS:
var page = require('webpage').create();
page.onConsoleMessage = function(msg) {
console.log('here i am');
};
page.onLoadFinished = function() {
console.log('or here!');
}
page.open('http://localhost:3456/calculatorfixture.html', function (status) {
waitFor(function _test(){
return page.evaluate(function() {
return document.getElementById("test").innerHTML == "something";
});
}, function _onReady(){
console.log ("DONE");
phantom.exit();
});
});
我正在截圖也 - 依然,沒有什麼。我無法使用任何JS在我的頁面上工作。我錯過了什麼?
我確實擁有它。正好在我放的js代碼之上。 – mmmm
您應該更新您的問題以顯示完整的代碼以及預期的輸出。如果我的本地測試給出了正確的結果,我傾向於認爲您的配置中存在另一個問題。您是否在http:// localhost:3456/calculatorfixture.html驗證了內容,行爲和JS錯誤的缺失?嘗試將其剝離到要點並再次測試。 –