Angularjs 量角器-如何获取我刚刚执行操作的元素?

Angularjs 量角器-如何获取我刚刚执行操作的元素?,angularjs,Angularjs,我正在使用量角器为用AngularJS编写的应用程序编写一些e2e测试,我想执行以下任务: element(by.id('btn1')).click().then(function() { // I want to get the element that I just clicked, and check its label // How I can pass (if possible) the element to the then() function? }); 目前

我正在使用量角器为用AngularJS编写的应用程序编写一些e2e测试,我想执行以下任务:

element(by.id('btn1')).click().then(function() {
     // I want to get the element that I just clicked, and check its label
     // How I can pass (if possible) the element to the then() function?
});
目前我所做的是:

element(by.id('btn1')).click().then(function() {
     expect(element(by.id('btn1')).getText()).toBe('cancel');
});
提前感谢,, Kai

问题是,promise的类型是
webdriver.promise.promise.
因此没有传递任何内容到解析器

只需将元素引用存储在变量中即可重复使用

var btn = element(by.id('btn1'));
btn.click().then(function() {
    expect(btn.getText()).toEqual('cancel');
});