Protractor : wait for element to become invisible/hidden
Asked Answered
T

4

22

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,

Thuja answered 16/10, 2014 at 18:38 Comment(0)
C
16

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));
Counterespionage answered 28/12, 2014 at 15:29 Comment(6)
However, I ran into another issue, I will post another question which is related to this.Thuja
here is that post. #28422511Thuja
I can't find any documentation at all for protractor.until. What is it? What does it do?Golconda
protractor.until is undefined for me.Albertinealbertite
from the protractor api, you can do: var EC=protractor.ExpectedConditions; browser.wait(EC.not(EC.presenceOf(el));Intensifier
@Golconda protractor.until is a reference to the until module in the selenium-webdriver package. It is used in the first example in their README file: npmjs.com/package/selenium-webdriverFontaine
D
8

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

Decalcify answered 7/2, 2017 at 22:16 Comment(1)
This will throw an error on EC.presenceOf(el) so it will not get the "not"Embowel
C
1

Protractor now has invisibilityOf function built in.

var EC = protractor.ExpectedConditions;
// Waits for the element with id 'abc' to be no longer visible on the dom.
browser.wait(EC.invisibilityOf($('#abc')), 5000);

Read more for details

Clinic answered 4/9, 2020 at 14:59 Comment(0)
E
0

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);
 });
});
Earlearla answered 19/2, 2018 at 8:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.