Thangakumar D
Thangakumar D

Reputation: 774

protractor + cucumber - element not visible even though element is visible

 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

Upvotes: 1

Views: 1039

Answers (1)

mrfreester
mrfreester

Reputation: 1991

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.

Upvotes: 1

Related Questions