量角器+黄瓜 - 即使元素可见,元素也不可见 [英] protractor + cucumber - element not visible even though element is visible

查看:144
本文介绍了量角器+黄瓜 - 即使元素可见,元素也不可见的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

< pre class =snippet-code-js lang-js prettyprint-override> this.When(/ ^用户点击登录按钮$ /,function(){return browser.wait(wagLoginPage.loginPage .signIn.isPresent()。then(function(visible){if(visible){console.log(element is visible !!!!!!!); wagLoginPage.loginPage.signIn.click()。then(function) (){expect(visible).to.be.true;});} else {expect(visible).to.be.true;}},function(){chai.assert.isFalse(true,SingIn not not not可见!)}));});





我的测试在上面的步骤中随机失败。对于上面的代码,在控制台窗口中,量角器打印'元素是可见的'。但是,如果我对元素执行click事件,则抛出元素不可见异常。



更新



回答问题 here

解决方案

您的元素存在,但可能不可见。



试试这个:

 返回browser.wait(wagLoginPage.loginPage.signIn.isDisplayed()。then(function(可见){
//你的东西
}

注意,我是使用 isDisplayed() isPresent()



isPresent()是如果您正在检查某个元素是否在页面上,但可能会显示或不显示,则非常有用。



isDisplayed()如果您有用检查元素是否在页面上可见。


 this.When(/^the user clicks on login button$/, function () {
        return browser.wait(wagLoginPage.loginPage.signIn.isPresent().then(function (visible) {            
            if(visible){
                console.log("element is visible !!!!!!!");
                wagLoginPage.loginPage.signIn.click().then(function(){
                     expect(visible).to.be.true;
                });
            }
            else{
                expect(visible).to.be.true;
            }           
        }, function () { chai.assert.isFalse(true, "SingIn is not visible!") }));
    });

My test randomly fails in the above step. For the above code, in console window protractor prints 'element is visible'. But if I perform click event on the element it throws element is not visible exception.

Update

Questions is answered here

解决方案

Your element is present, but it's probably not visible.

Try this:

return browser.wait(wagLoginPage.loginPage.signIn.isDisplayed().then(function (visible){
    //Your stuff
}

Note, I'm using isDisplayed() vs. isPresent().

isPresent() is useful if you are checking if an element is on the page, but may or may not be visible.

isDisplayed() is useful if you are checking if an element is visible on the page.

这篇关于量角器+黄瓜 - 即使元素可见,元素也不可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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