angularjs - 如何处理 Protractor 中的模态对话框?

标签 angularjs selenium modal-dialog protractor

我正在尝试在 this 上的模态对话框上使用 sendKeys()网站。单击登录 按钮后会出现此对话框。我似乎无法找到任何方法来将焦点切换到框上。查看gist

我尝试在

中使用 browser.driver.switchTo().activeElement();
InvalidLogInUnSuccess: {
        get: function () {
            this.loginButton.click();
            browser.driver.switchTo().activeElement();
            this.email.sendKeys("Test");
        }
    }

运气不好并抛出 ElementNotVisibleError

Message: ElementNotVisibleError: element not visible (Session info: chrome=41.0.2272.101) (Driver info: chromedriver=2.14.313457 (3d645c400edf2e2c500566c9aa096063e707c9cf),platform=Windows NT 6.3 x86_64) Stacktrace: ElementNotVisibleError: element not visible

最佳答案

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

visibilityOf expected condition在这种情况下对我有用:

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

email.sendKeys('test');

EC 是我通常在 onPrepare() 中全局定义的内容:

onPrepare: function () {
    ...

    global.EC = protractor.ExpectedConditions;
},

只是旁注,我认为可以在此处改进定位器:

  • ng-scope 不是我会依赖的东西
  • email字段上定义了一个model,怎么样:

    element(by.model('email'));
    

仅供引用,我执行的完整规范:

"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');
        });

    });
});

关于angularjs - 如何处理 Protractor 中的模态对话框?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29323717/

相关文章:

python - Selenium 和新标签

javascript - 如何在 NightwatchJS 中对元素列表进行断言

c# - Bootstrap 模式未显示在 ASP.NET GridView 模板按钮上单击

Angularjs ng-show指令将 'N'和 'NO'解释为虚假值

javascript - 一定宽度的裁剪跨度

javascript - Angular Directive(指令)不应用样式

Jquery 模态工具提示插件

angularjs - chai-as-promised 测试不适用于 $q promise

java - 线程 "main"org.openqa.selenium.ElementNotVisibleException : Element is not currently visible and so may not be interacted with 中出现异常

html - 如何禁用 IE 中模式对话框的缓存?