admin管理员组文章数量:1130349
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 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();
The spec.
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
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 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();
The spec.
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
Share Improve this question edited Feb 6, 2017 at 19:57 theHussle asked Feb 2, 2017 at 21:54 theHussletheHussle 3213 silver badges19 bronze badges2 Answers
Reset to default 7You will see Failed: unknown error: cannot focus element error when you are trying to sendKeys() to an element which is not an input
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
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);
}
};
Figured this one out:
var input = firstName.element(by.css('input')); //declare the input
browser.actions().click(input).sendKeys("owiejf").perform(); //sendkeys
where browser is the name that's declared here
import { browser, element, by, ElementFinder } from 'protractor';
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 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();
The spec.
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
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 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();
The spec.
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
Share Improve this question edited Feb 6, 2017 at 19:57 theHussle asked Feb 2, 2017 at 21:54 theHussletheHussle 3213 silver badges19 bronze badges2 Answers
Reset to default 7You will see Failed: unknown error: cannot focus element error when you are trying to sendKeys() to an element which is not an input
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
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);
}
};
Figured this one out:
var input = firstName.element(by.css('input')); //declare the input
browser.actions().click(input).sendKeys("owiejf").perform(); //sendkeys
where browser is the name that's declared here
import { browser, element, by, ElementFinder } from 'protractor';
本文标签:
版权声明:本文标题:javascript - Protractor, Failed: unknown error: cannot focus element on custom input field - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1741720881a1884497.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论