protractor + cucumber - element not visible even t

2019-05-30 17:51发布

 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!") }));
    });

Protractor - element is not visible issue

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

1条回答
ら.Afraid
2楼-- · 2019-05-30 18:11

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.

查看更多
登录 后发表回答