无法使用casperjs evaluate和__doPostBack函数进行导航 [英] Cannot navigate with casperjs evaluate and __doPostBack function

查看:97
本文介绍了无法使用casperjs evaluate和__doPostBack函数进行导航的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试在具有href为__doPostBack函数调用的链接的网站上导航分页时,我从未实现页面更改。



我不确定我错过了什么,所以经过几个小时的乱搞后我决定看看这里有人能给我一些线索。
这是我的代码(uber-simplified来显示用例)。

  var casper = require('casper ')。create({
verbose:true,
logLevel:debug
});
casper.start('http://www.gallito.com.uy/inmuebles/venta');
//这里我模拟了分页列表中链接的点击
casper.evaluate(function(){
__doPostBack('RptPagerDos $ ctl08 $ lnkPage2','');
});
casper.then(function(){
console.log('new location is'+ this.getCurrentUrl());
var i = casper.evaluate(function(){
返回$(。aspNetDisabled)。text();
});
console.log(i);
});
casper.run();

我尝试使用casper的click()和一个简单的jQuery点击evaluate,但这不起作用,因为href是对__doPostBack函数的调用。



我使用的是casperjs 1.1.0-beta3和phantomjs 1.9.7。我检查了类似的问题,我看到这篇文章 CasperJS:如何调用__doPostBack 但是解决方案对我不起作用,显然它也不适用于OP。



提前致谢。如果您需要更多详细信息,请与我们联系。

解决方案

我通过更改



<$ p $来导航分页p> casper.evaluate(function(){
__doPostBack('RptPagerDos $ ctl08 $ lnkPage2','');
});

对此:

  casper.then(
function(){
casper.evaluate(function(){
var insertHTML ='< input type =hiddenname =__ EVENTTARGET id =__ EVENTTARGETvalue =/>< input type =hiddenname =__ EVENTARGUMENTid =__ EVENTARGUMENTvalue =/>< input type =hiddenname =__ LASTFOCUS id =__ LASTFOCUSvalue =/>';
$(#Form1 .aspNetHidden)。html(insertHTML);

$(#Form1 .aspNetHidden# __EVENTTARGET)。val('RptPagerDos $ ctl04 $ lnkPage2');


$(#Form1)。submit();

});
}
);

我注意到即使尝试直接提交表单也是一个问题,看起来出于某种原因,它没有找到它需要的元素(我尝试了casper的fill()函数并且因为表单输入不存在而崩溃了)


When I try to navigate the pagination on sites with links where href is a __doPostBack function call, I never achieve the page change.

I am not sure what I am missing, so after a few hours of messing around I decided to see if someone here can give me a clue. This is my code (uber-simplified to show the use case).

var casper = require('casper').create({
    verbose: true,
    logLevel: "debug"
});
casper.start('http://www.gallito.com.uy/inmuebles/venta');
// here i simulate the click on a  link in the pagination list
casper.evaluate(function() {
    __doPostBack('RptPagerDos$ctl08$lnkPage2','');
});
casper.then(function() {
    console.log(' new location is ' + this.getCurrentUrl());
    var i=casper.evaluate(function(){
        return $(".aspNetDisabled").text();
    });
    console.log(i);
});
casper.run();

I tried with casper's click() and a simple jQuery click on evaluate, but that does not work because the href is a call to the __doPostBack function.

I am using casperjs 1.1.0-beta3 and phantomjs 1.9.7. I checked for similar issues and I saw this post CasperJS : how to call __doPostBack but the solution there does not work for me, and apparently it did not work for the OP either.

Thanks in advance. Please let me know if you need any more details.

解决方案

I was able to navigate the pagination by changing

casper.evaluate(function() {
    __doPostBack('RptPagerDos$ctl08$lnkPage2','');
});

To this:

casper.then(
    function(){
        casper.evaluate(   function() {
            var insertHTML='<input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="" /><input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT" value="" /><input type="hidden" name="__LASTFOCUS" id="__LASTFOCUS" value="" />';
            $("#Form1 .aspNetHidden").html(insertHTML);

            $("#Form1 .aspNetHidden #__EVENTTARGET").val('RptPagerDos$ctl04$lnkPage2');


            $("#Form1").submit();

        });
    }
);

I noticed that even trying to submit the form directly was a problem, it looks like for some reason, it was not finding the elements it needed (i tried casper's fill() function and got crashes because the form inputs were not present)

这篇关于无法使用casperjs evaluate和__doPostBack函数进行导航的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆