protractor + cucumber - element not visible even t

2019-05-30 17:53发布

问题:

 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

回答1:

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.