等待一个Ajax调用来完成与硒2网络驱动器 [英] wait for an ajax call to complete with Selenium 2 web driver

查看:171
本文介绍了等待一个Ajax调用来完成与硒2网络驱动器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是硒2网络驱动程序来测试用户界面,它使用AJAX。

有没有办法让司机等候一下,让Ajax请求将完成

基本上我有这样的:

  d.FindElement(By.XPath(// DIV [8] / DIV [3] / DIV /按钮))点击();
//这个^点击触发这将填补下面的编号与内容Ajax请求
//所以我需要让等待位

Assert.IsNotEmpty(d.FindElement(By.Id(爱好))文本。);
 

解决方案

  VAR等待=新WebDriverWait(D,TimeSpan.FromSeconds(5));
VAR元= wait.Until(驱动程序=> driver.FindElement(By.Id(爱好)));
 

I'm using selenium 2 web driver to test an ui which uses AJAX.

Is there a way to make the driver to wait for a bit so that the ajax request will complete

basically I have this:

d.FindElement(By.XPath("//div[8]/div[3]/div/button")).Click();
// this^ click triggers an ajax request which will fill the below Id with content
// so I need to make it wait for a bit

Assert.IsNotEmpty(d.FindElement(By.Id("Hobbies")).Text);

解决方案

var wait = new WebDriverWait(d, TimeSpan.FromSeconds(5));
var element = wait.Until(driver => driver.FindElement(By.Id("Hobbies")));

这篇关于等待一个Ajax调用来完成与硒2网络驱动器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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