等待 Selenium Webdriver 更改的最佳实践? [英] Best practice to wait for a change with Selenium Webdriver?

查看:23
本文介绍了等待 Selenium Webdriver 更改的最佳实践?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在单击事件之后,我需要等待元素属性发生变化才能继续进行(单击事件会导致某些元素移出焦点,而某些其他元素通过 JS 获得焦点)

After a click event I need to wait for an elements attribute to change before proceeding further (click event causes certain elements to move out of focus and certain others get focus via a JS)

在 Web 驱动程序中花费时间搜索waitForAttribute"(selenium 1 命令)的可靠替代方案后……我可以让下面的代码工作.但我不确定这是否是最好的实现......

After spending time searching for a reliable alternative to "waitForAttribute" (selenium 1 command) in web driver... I could get the below code to work. But I am not sure if this is the best implementation...

还有其他更好的解决方案吗??

Any other better solution??

wait = new WebDriverWait(wedriver1, TimeSpan.FromSeconds(5));
.....
button.Click();
wait.Until(webdriver1 => webdriver2.webelement.GetAttribute("style").Contains("display: block"));

另外,任何人都可以分享我如何使用 webdriver 处理 AJAX 事件更改的链接.

Also, can anyone please share a link to how I can handle AJAX event changes using webdriver.

推荐答案

这是 Selenium 的一个反复出现的问题.我不确定是否存在最佳"实现.我认为这在很大程度上取决于情况.

It's a recurring problem of Selenium. I am not sure about a "best" implementation existing. I believe it's largely depending on the situation.

关于 AJAX 驱动的更改,我通常会使用 waitForElementPresent 或 waitForElementNotPresent,具体取决于 AJAX 调用将在页面上进行的更改.

Concerning AJAX-driven changes, I would generally use a waitForElementPresent or a waitForElementNotPresent depending on the changes the AJAX call will make on the page.

这篇关于等待 Selenium Webdriver 更改的最佳实践?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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