nhrcpt
nhrcpt

Reputation: 872

Protractor - How to validate that an element is not visible

This question is closely related to the solutions given in this question

In my test script, I need to go to login script and need to logout in case the browser logs in automatically in the app. So following the solutions provided in the question How to create a condition in protractor for when an element exists or not, I have created this script:

 beforeEach(function () {
    browser.driver.manage().window().maximize();
    browser.get(globalVariables.loginMain);
    globalVariables.User_Menu_Dropdown.isDisplayed().then(function(Login_Menu) {

        if (Login_Menu) {

            globalVariables.User_Menu_Dropdown.click();
            browser.wait(globalVariables.until.presenceOf(globalVariables.logOut_Button), 3000, 'The Logout menu too long to appear in the DOM');
            globalVariables.logOut_Button.click();
            browser.wait(globalVariables.until.presenceOf(globalVariables.Email_Input_box), 3000, 'The User Input box too long to appear in the DOM');
        } else {

            console.log("the app is on the login page")//do nothing

        }

    });

But when I run the script, I still get the following error "Failed: No element found using locator: By(css selector, img[class="img-thumb-xs mr-1 align-middle"])". What am I doing wrong here? What is the best approach to achieve it?

Upvotes: 0

Views: 90

Answers (1)

Infern0
Infern0

Reputation: 2814

you can use the ExpectedConditions in your case.

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);

or you can use the not condition which will lead to the same result

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

Upvotes: 1

Related Questions