此问题与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"])".我在这里做错了什么?实现它的最佳方法是什么?

最佳答案

您可以在您的情况下使用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);

关于javascript - Protractor -如何验证元素不可见,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/54190517/

10-11 12:27
查看更多