How to change current page in Phantomjs using buttons? [duplicate]

你离开我真会死。 提交于 2019-12-31 05:11:28

问题


I have start to using Phantomjs and I don't understand something. How to change current page using buttons? For example I've got a code:

var page = require('webpage').create();

page.open('https://ru-ru.facebook.com', function() {
    page.injectJs('jQuery.js');
        page.evaluate(function() {
        $('#email').val('MyLogin');
        $('#pass').val('MyPass');
        $('#u_0_l').click();
        });
    page.render('example.png');
    phantom.exit();
});

So after clicking a button I need to go to the next page. How can I do this?


回答1:


Assuming the $.click() actually worked, you need to wait until the page has loaded.

setTimeout:

You may feel lucky and try it with

page.evaluate(function() {
    // form vals and click
});
setTimeout(function(){
    page.render('example.png');
    phantom.exit();
}, 3000); // 3 sec timeout

waitFor selector:

You may use the waitFor example from the phantomjs package to wait for an element that you know is only on the loaded page, but not on the current page.

waitFor loadFinished:

You may combine waitFor with the onLoadFinished callback handler to do wait for the next page to load. This is preferable since this would work every time and would not impose overshooting with a conservative timeout.

Just use CasperJS:

Nothing more to add.



来源:https://stackoverflow.com/questions/25228685/how-to-change-current-page-in-phantomjs-using-buttons

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!