1

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?

alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
awaken
  • 789
  • 1
  • 11
  • 22

1 Answers1

2

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");
    });
});
alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
  • thanks for the reply but whats the explanation on why wrapping makes it not refer to the page object? – awaken Apr 03 '15 at 01:54
  • @awaken I think the current execution context is not the page object in this case, please see http://stackoverflow.com/questions/3127429/how-does-the-this-keyword-work. – alecxe Apr 03 '15 at 02:04