硒在Chrome中等待AJAX [英] Selenium waiting for AJAX in Chrome

查看:96
本文介绍了硒在Chrome中等待AJAX的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用Selenium来自动化网站测试。部分测试涉及等待AJAX​​请求完成。我已经使用这一行来做到这一点与jQuery 1.4:

I've been using Selenium to automate website testing. Part of the tests involves waiting for AJAX requests to finish. I've been using this line to do that with jQuery 1.4:

selenium.WaitForCondition("selenium.browserbot.getCurrentWindow().jQuery.active == 0", "5000");

在Chrome和Firefox 4中运行良好,但不支持IE9。然后我升级到jQuery 1.5,并且它奇迹般地停止了在Chrome中的工作。我尝试了以下变化,但它们都不起作用:

It worked fine in Chrome and Firefox 4, but not IE9. Then I upgraded to jQuery 1.5, and it magically stopped working in Chrome. I've tried the following variations, but none of them work:

selenium.WaitForCondition("selenium.browserbot.getCurrentWindow().jQuery.active == 0", "5000");
selenium.WaitForCondition("selenium.browserbot.getCurrentWindow().jQuery.ajax.active == 0", "5000");
selenium.WaitForCondition("selenium.browserbot.getCurrentWindow().$.active == 0", "5000");
selenium.WaitForCondition("selenium.browserbot.getCurrentWindow().$.ajax.active == 0", "5000");

SeleniumException是它无法读取属性 active ajax 的未定义,所以我想它有点不能到达jQuery。我的同事在Firefox 4上运行相同的测试,并且他们通过。

The SeleniumException is that it cannot read property active or ajax of undefined, so I guess it's somehow not able to get to jQuery. My colleague is running the same tests on Firefox 4, and they pass.

有没有人遇到过这个问题?任何建议?

Has anyone experienced this issue? Any suggestions?

推荐答案

显然,Selenium中的所有东西都可以通过随机抛出 Thread.Sleep()小号。窗口在某些情况下还没有完成加载,这就是 $ 未定义的原因。

Apparently everything in Selenium can be fixed by throwing in random Thread.Sleep()s. The window hadn't finished loading in some cases, that's why $ was undefined. I put a sleep before the wait, and it works fine now.

我不得不使用以下行:

I had to use the following line:

selenium.WaitForCondition("selenium.browserbot.getCurrentWindow().$.active == 0", "5000");

即使人们说我应该使用 $。ajax.active 如果我使用jQuery 1.5,它对我来说是未定义的,而 $ .active 可以工作。

Even though people are saying I should have used $.ajax.active if I'm using jQuery 1.5, it's undefined for me, whereas $.active works.

这篇关于硒在Chrome中等待AJAX的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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