如何使用按钮在Phantomjs中更改当前页面? [英] How to change current page in Phantomjs using buttons?
问题描述
var page = require('
page.open('https://ru-ru.facebook.com',function(){
page.injectJs('jQuery.js');
页面val('MyPass');
$('MyPage');
$ ('#u_0_l')。click();
});
page.render('example.png');
phantom.exit();
});
所以点击一个按钮后,我需要去下一页。我该怎么做?
假设 $。click()
实际工作,您需要等到页面加载。
setTimeout:
您可能会感到幸运,并尝试使用
page.evaluate(function(){
// form vals并点击
});
setTimeout(function(){
page.render('example.png');
phantom.exit();
},3000); // 3秒超时
waitFor selector:
您可以使用 waitFor 例如从phantomjs包等待一个你知道的元素只在加载的页面上,但不在当前页面上。
waitFor loadFinished: / strong>
您可以组合 onLoadFinished 回调的nofollow> waitFor 处理程序要等待下一页加载。这是可取的,因为这样做会每次都工作,不会超过保守的超时。
只需使用 CasperJS :
无需添加。
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?
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.
这篇关于如何使用按钮在Phantomjs中更改当前页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!