量角器-如何验证元素不可见

时间:2019-01-14 23:04:57

标签: javascript jasmine protractor

这个问题与question

中给出的解决方案密切相关

在我的测试脚本中,我需要进入登录脚本并注销,以防浏览器自动在应用程序中登录。因此,按照问题How to create a condition in protractor for when an element exists or not中提供的解决方案,我创建了以下脚本:

 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

        }

    });

但是当我运行脚本时,仍然出现以下错误 "Failed: No element found using locator: By(css selector, img[class="img-thumb-xs mr-1 align-middle"])".我在做什么错?实现它的最佳方法是什么?

1 个答案:

答案 0 :(得分:1)

您可以根据情况使用 ExpectedConditions

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

或者您可以使用 not 条件,这将导致相同的结果

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);
相关问题