Protractor : wait for element to become invisible/

2019-02-07 22:05发布

I saw other protractor related post mentioning about how to wait for an element to become visible. However, recently, I ran into an opposite use case. I wanted to wait for an element until it becomes invisible. Since I could not find anything specific about it. I went ahead and came up with a solution.

var ptor = protractor.getInstance();
    ptor.wait(function() {

        return element(by.css('#my-css-here')).isDisplayed().then(function(isVisible){
            console.log('is visible :' + isVisible);
            return !isVisible;
        });

    }, 12000).then(function(){
        //do whatever you want 
});

hopefully it helps. any suggestion is welcome.

Thanks,

3条回答
Juvenile、少年°
2楼-- · 2019-02-07 22:46

From @Machtyn This should be the correct answer: var EC=protractor.ExpectedConditions; browser.wait(EC.not(EC.presenceOf(el)), someTimeoutInMilli);

查看更多
We Are One
3楼-- · 2019-02-07 22:56

Using the elementexplorer (https://github.com/angular/protractor/blob/master/docs/debugging.md) I looked at the protractor object and found an answer that is working wonderfully for me:

var el = element(by.id('visibleElementId'));
browser.driver.wait(protractor.until.elementIsNotVisible(el));
查看更多
一夜七次
4楼-- · 2019-02-07 22:56

None of the solution working for me. Please take a look at below code:

var protractor = require('protractor');

describe('Testing', function () {
it('Should show the settings button', function () {
    var EC = protractor.ExpectedConditions;
    var settings = $('.settings');
    var isSettingVisible = EC.visibilityOf(settings);

    browser.get('http://localhost:8080/#/edomonitor');
        console.log("--------------------welcome 1-------------------");

    protractor.browser.wait(isSettingVisible, 10000, "Searching for settings").then(() => {
       console.log("waiting complete");
    }, (error) => {
       console.log(error);
    })
    expect(2).toEqual(2);
 });
});
查看更多
登录 后发表回答