如何处理量角器中的模态对话框?

Sai*_*fur 2 selenium modal-dialog angularjs protractor

我试图sendKeys()网站的模态对话框上使用。单击“ 登录”按钮后,将出现此对话框。我似乎找不到任何将焦点转移到盒子上的方法。见要点

我尝试browser.driver.switchTo().activeElement();

InvalidLogInUnSuccess: {
        get: function () {
            this.loginButton.click();
            browser.driver.switchTo().activeElement();
            this.email.sendKeys("Test");
        }
    }
Run Code Online (Sandbox Code Playgroud)

运气不好并抛出ElementNotVisibleError

消息:ElementNotVisibleError:元素不可见(会话信息:chrome = 41.0.2272.101)(驱动程序信息:chromedriver = 2.14.313457(3d645c400edf2e2c500566c9aa096063e707c9cf),platform = Windows NT 6.3 x86_64)Stacktrace:ElementNotVisibleError:元素不可见

ale*_*cxe 5

在使用动画效果打开弹出窗口时,我在测试内部应用程序时遇到了类似的问题(我认为这是罪魁祸首),这使我考虑等待弹出窗口中的元素变得可见。

visibilityOf在这种情况下,预期条件对我有效:

var email = element(by.css('.container.login.ng-scope #email'));
browser.wait(EC.visibilityOf(email), 5000);

email.sendKeys('test');
Run Code Online (Sandbox Code Playgroud)

这里EC是我通常在全局范围内定义onPrepare()

onPrepare: function () {
    ...

    global.EC = protractor.ExpectedConditions;
},
Run Code Online (Sandbox Code Playgroud)

只是一点说明,我认为可以在此处改进定位器:


仅供参考,我执行的完整规格说明:

"use strict";

describe("gifteng test", function () {
    var scope = {};

    beforeEach(function () {
        browser.get("http://www.gifteng.com/?login");
        browser.waitForAngular();
    });

    describe("Logging in", function () {
        it("should send keys to email", function () {
            var email = element(by.css('.container.login.ng-scope #email'));
            browser.wait(EC.visibilityOf(email), 5000);

            email.sendKeys('test');
        });

    });
});
Run Code Online (Sandbox Code Playgroud)