量角器,失败:未知错误:无法将元素集中在自定义输入字段上 [英] Protractor, Failed: unknown error: cannot focus element on custom input field
问题描述
跳上测试车,现在正在实施一些网站的E2E测试,但我遇到了一个棘手的小问题。
Jumped on the testing wagon and now implementing some E2E tests of a website, but I have run into a troublesome little issue.
我正试图选择一个然后将字段发送到该输入字段以更改值,唯一的问题是失败:未知错误:无法聚焦元素错误我似乎无法过去。我有它在其他领域工作,只是没有这个设置。
I'm trying to select a field then send keys to that input field to change the value, the only problem is the Failed: unknown error: cannot focus element error I can't seem to get past. I have it working on other fields, just not ones with this setup.
pageObject文件。
pageObject file.
var profilePage = function() {
this.firstName = element(by.id('firstname'));
this.lastName = element(by.id('lastname'));
this.saveBtn = element(by.css('ng-click="saveLocalAccount()"'));
this.cancelBtn = element(by.css('ng-click="cancelChanges()"'));
this.changeName = function(firstname, lastname) {
this.firstName.click();
var input = firstName.element(by.css('input'));
input.click();
this.input.sendKeys(firstname);
this.lastName.click();
this.lastName.sendKeys(lastname);
browser.waitForAngular();
}
};
module.exports = new profilePage();
规格。
var profilePage = require('TestProtractor/E2E/PageObjects/profile.pageObject.js');
describe('Testing the profile page functionality', function() {
var firstNameTest = "firstTest";
var lastNameTest = "lastTest";
it('Navigate to profile page.' ,function() {
browser.get('xxx');
expect(browser.getCurrentUrl())
.toContain('xxx');
});
it('Should change the firstname and lastname successfully', function() {
profilePage.changeName(firstNameTest, lastNameTest);
expect(element(by.id('firstname')).getText()).toContain(firstNameTest);
expect(element(by.id('lastname')).getText()).toContain(firstNameTest);
});
});
html
推荐答案
您将看到失败:unkno wn错误:无法聚焦元素错误
当您尝试将 sendKeys()
添加到不是输入<的元素时/ code>
You will see Failed: unknown error: cannot focus element error
when you are trying to sendKeys()
to an element which is not an input
在您可重复使用的方法中 changeName()
您正在尝试 sendKeys()
进入 lastName = element(by.id('lastname'))
这不是输入
元素。您必须以与输入名字文字相同的方式接近它
In your re-usable method changeName()
you are trying to sendKeys()
into lastName = element(by.id('lastname'))
which is not an input
element. You have to approach it in the same way as you were entering text for first name
假设它们是输入
在lastname里面
Assuming their is an input
inside lastname too
this.changeName = function(firstname, lastname) {
this.firstName.click();
var input = firstName.element(by.css('input'));
input.click();
this.input.sendKeys(firstname);
this.lastName.click();
var input2 = lastName.element(by.css('input'));
input2.click();
this.input2.sendKeys(lastName);
}
};
这篇关于量角器,失败:未知错误:无法将元素集中在自定义输入字段上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!