Q:

protractor executeScript weirdness with ElementArrayFinder

I have this declared in my Page Object:
this.paginationPageNumberList = element.all(by.repeater("page in pages track by $index"));

Running this inside a function of Page Object, its successful and prints 'no wrap':
browser.executeScript('window.scrollTo(254,1600);');
this.paginationPageNumberList.get(0).then(function() {
    console.log("no wrap");
});

Running the same thing except with a then() gives me an error:
browser.executeScript('window.scrollTo(254,1600);').then(function () {
    this.paginationPageNumberList.get(0).then(function() {
        console.log("wrap");
    });
});

Failed: Cannot call method 'get' of undefined.

Why?

A:

I'm afraid this in this case is not referring to the page object.
Instead, make a separate variable:
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");
    });
});

