我正在运行github张贴的示例作为量角器。当我运行示例时,我收到错误:
NoSuchElementError:找不到使用locator的元素:by.model(“todoText”)
我使用网站上列出的相同设置:
describe('angularjs homepage todo list', function() {
it('should add a todo', function() {
browser.get('http://www.angularjs.org');
element(by.model('todoText')).sendKeys('write a protractor test');
element(by.css('[value="add"]')).click();
var todoList = element.all(by.repeater('todo in todos'));
expect(todoList.count()).toEqual(3);
expect(todoList.get(2).getText()).toEqual('write a protractor test');
});
});
exports.config = {
seleniumAddress: 'http://localhost:4444/wd/hub',
specs: ['test/e2e/app/todo-spec.js']
};
我尝试将值更改为todoList
。这也失败了。
答案 0 :(得分:3)
看起来ng-model的值是角网站上的todoList.todoText所以......
element(by.model('todoList.todoText')).sendKeys('write a protractor test');
可能
var todoList = element.all(by.repeater('todo in todoList.todos'));
答案 1 :(得分:0)
以下是适用的todo-spec.js版本:
describe('angularjs homepage todo list', function() {
it('should add a todo', function() {
browser.get('http://www.angularjs.org');
element(by.model('todoList.todoText')).sendKeys('write a protractor test');//correction
element(by.css('[value="add"]')).click();
var todoList = element.all(by.repeater('todo in todoList.todos'));//correction
expect(todoList.count()).toEqual(3);
expect(todoList.get(2).getText()).toEqual('write a protractor test');
});
});