如何添加等待方法,直到在ruby + Cucumber2.0中加载特定元素之前 [英] How to add a wait method to wait until a specific element is loaded in ruby+Cucumber2.0

查看:100
本文介绍了如何添加等待方法,直到在ruby + Cucumber2.0中加载特定元素之前的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在浏览器堆栈上测试我的案件时遇到问题。所面临的问题不一致地重现了。

I have a problem while testing my cases on browser stack. The problem am facing is inconsistently reproduced.

要让我的代码等到元素加载完毕,请按以下方式使用:

To make my code wait until an element is loaded am using as below:

gift_no_btn1 = Capybara.find('giftingNoButton')
gift_no_btn1.click

这里的问题是屏幕卡在了其他模块中,在该模块中未加载我的预期元素,因此脚本失败了。我已经读过Capybara 2.0中的find()方法已替换为wait_untill方法。

The problem here is that the screen is stuck in the other module where my intended element is not loaded and hence my script fails. I have read that find() method is replaced of wait_untill method in Capybara 2.0.

推荐答案

Capybaras的查找方法将一直等待Capybara .default_max_wait_time秒,以显示匹配的元素。如果他们没有等待足够长的时间,可以使用:wait选项增加该设置或将其覆盖以进行特定查找,例如

Capybaras find methods will wait up to Capybara.default_max_wait_time seconds for a matching element to appear. If they are not waiting long enough either increase that setting or override it for a specific find with the :wait option like

page.find :css, 'CSS selector for the element', wait: 10

最多等待10个元素存在的秒数。在您的示例中,您要传递CSS选项 giftingNoButton,除非您使用自定义元素,否则它实际上是无效的。您可能需要 #giftingNoButton(查找ID匹配)或 .giftingNoButton(类匹配)

which will wait up to 10 seconds for the element to exist. In your example you're passing a CSS selector of 'giftingNoButton' which isn't really valid unless you're using custom elements. You probably want '#giftingNoButton' (find id matching) or '.giftingNoButton' (class matching)

这篇关于如何添加等待方法,直到在ruby + Cucumber2.0中加载特定元素之前的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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