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

为君一笑 提交于 2019-12-23 03:52:12

问题


 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.



来源:https://stackoverflow.com/questions/43333350/protractor-cucumber-element-not-visible-even-though-element-is-visible

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!