CasperJS单击具有AJAX调用事件 [英] CasperJS click event having AJAX call

查看:235
本文介绍了CasperJS单击具有AJAX调用事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图通过模拟使用CasperJS与phantomJS 1.7.0事件从网站获取数据。

I am trying to fetch data from a site by simulating events using CasperJS with phantomJS 1.7.0.

我能够模拟正常的单击事件并选择事件。但是,在以下情况下我的code失败:

I am able to simulate normal click events and select events. But my code fails in following scenario:

当我点击按钮/锚等远程页面上远程页面的点击启动AJAX调用/ JS调用(具体取决于该网页是通过编程来实现)。

When I click on button / anchor etc on remote page, the click on remote page initiates an AJAX call / JS call(depending on how that page is implemented by programmer.).

在的情况下JS调用的,我的code ++工程,我得到改变的数据。但点击的AJAX调用开始的地方,我没有更新数据。

In case of JS call, my code works and I get changed data. But for clicks where is AJAX call is initiated, I do not get updated data.

有关调试,我试图让元素容器(前,后)的网页源代码,但我看到在code没有变化。

For debugging, I tried to get the page source of the element container(before and after), but I see no change in code.

我试图设置等待时间从10秒到1毫秒的范围,但是,为了不反映在行为上的任何变化。

I tried to set wait time from 10 sec to 1 ms range, but that to does not reflect any changes in behavior.

下面是我的一块$ C $下点击。我使用的CSS路径,从而重新presents哪一个元素(S)的数组来点击。

Below is my piece of code for clicking. I am using an array of CSS Paths, which represents which element(s) to click.

/*Click on array of clickable elements using CSS Paths.*/
fn_click = function(){
casper.each(G_TAGS,function(casper, cssPath, count1) 
                    {
                            casper.then ( function() {
                            casper.click(cssPath);

                            this.echo('DEBUG AFTER CLICKING -START HTML ');
                            //this.echo(this.getHTML("CONTAINER WHERE DETAILS CHANGE"));
                            this.echo('DEBUG AFTER CLICKING -START HTML');
                            casper.wait(5000, function() 
                                                    {   

                                                        casper.then(fn_getData);
                                                    } 
                                    );
                            });     
                    });
};

更新:

我试图用从phantomJS远程调试选项,调试上面的脚本。 这是行不通的。我是在Windows上。我会尝试在Ubuntu上运行远程调试,以及。

I tried to use remote-debug option from phantomJS, to debug above script. It is not working. I am on windows. I will try to run remote debugging on Ubuntu as well.

请帮助我。我想AP preciate有这方面的帮助。

Please help me. I would appreciate any help on this.

更新:

请看看下面code作为样本。

Please have a look at following code as a sample.

https://gist.github.com/4441570

内容之前并单击后相同。

Content before click and after click are same.

我点击排序下标记(票/活动等)提供的选项。

I am clicking on sorting options provided under tag (votes / activity etc.).

推荐答案

今天我有同样的问题。我发现这个职位,这把我的jQuery的方向。

I had the same problem today. I found this post, which put me in the direction of jQuery.

在某些测试中,我发现,已经有一个jQuery装上该网页。 (A pretty的旧版本虽然)

After some testing I found out that there was already a jQuery loaded on that webpage. (A pretty old version though)

在上面加载其他的jQuery,打破任何的js调用而成,所以也是做一个Ajax调用的链接。

Loading another jQuery on top of that broke any js calls made, so also the link that does an Ajax call.

要解决这个问题,我发现 http://api.jquery.com/jQuery.noConflict/

To solve this I found http://api.jquery.com/jQuery.noConflict/

和我增加了以下到我的code:

and I added the following to my code:

    this.evaluate(function () { jq = $.noConflict(true) } ); 

这是以前分配到$任何信息都会被恢复的方式。而你注入了jQuery现在是JQ下可用。

Anything that was formerly assigned to $ will be restored that way. And the jQuery that you injected is now available under 'jq'.

希望这有助于你们。

这篇关于CasperJS单击具有AJAX调用事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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