如何处理量角器中的模态对话框? [英] How to handle modal-dialog box in Protractor?

查看:91
本文介绍了如何处理量角器中的模态对话框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在网站的模态对话框上使用sendKeys().单击登录按钮后,将显示此对话框.我似乎找不到任何将焦点转移到盒子上的方法.参见要点

I am trying to use sendKeys() on a modal-dialog box on this website. This dialog box appears after clicking Sign In button. I cannot seem to find any way to switch focus on the box. See the gist

我尝试在

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

没有运气并抛出 ElementNotVisibleError

消息: ElementNotVisibleError:元素不可见 (会议信息:chrome = 41.0.2272.101) (驱动程序信息:chromedriver = 2.14.313457(3d645c400edf2e2c500566c9aa096063e707c9cf),平台= Windows NT 6.3 x86_64) 堆栈跟踪: 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

推荐答案

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

I've experienced a similar issue while testing an internal application when a popup was being opened with an animation effect (I think it is a culprit here) which had me think about waiting for an element inside the popup to become visible.

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

visibilityOf expected condition works for me in this case:

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

email.sendKeys('test');

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

where EC is something I usually define globally in the onPrepare():

onPrepare: function () {
    ...

    global.EC = protractor.ExpectedConditions;
},


请注意,我认为可以在此处改进定位器:


Just a side note, I think the locator could be improved here:

  • ng-scope不是我要依靠的东西
  • email字段上定义了model,怎么做:

  • ng-scope is not something I would rely on
  • there is a model defined on the email field, how about:

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

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

FYI, the complete spec I've executed:

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

    });
});

这篇关于如何处理量角器中的模态对话框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆