如何在量角器中等待,直到元素启用 [英] How to wait in protractor till the element is enabled

查看:101
本文介绍了如何在量角器中等待,直到元素启用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试单击按钮时,量角器失败。最初,该按钮将处于禁用状态(某些时候它将被启用),并且量角器认为按钮已准备好并单击按钮并失败。

Protractor is failing when trying to click a button. Initially the button will be in disabled status (after sometime it will be enabled) and protractor thinks that the button is ready and clicking on the button and failing.

所以我希望量角器脚本等到按钮启用。我在下面尝试过,但它没有用。有人可以发布完整的代码来等待元素被启用吗?

So i want the protractor script to wait till the button is enabled. I have tried below, but it didn't work. Can someone please post the complete code to wait for the element to be enabled?

expect(browser.wait(function(){return browser.driver.isElementPresent(by.id('paynow-info-btn'))}, 10000));


推荐答案

有一个非常合适的预期条件 - elementToBeClickable - 它会等待一个元素可见并启用

There is a very much suitable Expected Condition - elementToBeClickable - it would wait for an element to be both visible and enabled:

var elm = element(by.id('paynow-info-btn'));
var EC = protractor.ExpectedConditions;

browser.wait(EC.elementToBeClickable(elm), 5000);
elm.click();

这篇关于如何在量角器中等待,直到元素启用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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