量角器 executeScript 与 ElementArrayFinder 的怪异

protractor executeScript weirdness with ElementArrayFinder

我在我的页面对象中声明了这个:

this.paginationPageNumberList = element.all(by.repeater("page in pages track by $index"));

运行 这在页面对象的函数中,它成功并打印 'no wrap':

browser.executeScript('window.scrollTo(254,1600);');
this.paginationPageNumberList.get(0).then(function() {
    console.log("no wrap");
});

运行 同样的事情,除了 then() 给我一个错误:

browser.executeScript('window.scrollTo(254,1600);').then(function () {
    this.paginationPageNumberList.get(0).then(function() {
        console.log("wrap");
    });
});

Failed: Cannot call method 'get' of undefined.

为什么?

恐怕this在这种情况下不是指页面对象

相反,制作一个单独的变量:

var paginationPageNumberList = element.all(by.repeater("page in pages track by $index"));
this.paginationPageNumberList = paginationPageNumberList;

browser.executeScript('window.scrollTo(254,1600);').then(function () {
    paginationPageNumberList.get(0).then(function() {
        console.log("wrap");
    });
});