我正在尝试在 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/