Scroll Protranslator through executeScript not working
I am testing my Ionic app.
On one page, the button you want to click is outside the window. Hence the following code:
element.all(by.css('.item.item-complex')).get(9).click();
gives an error message:
ElementNotVisibleError: element is not visible
Hence, I'm trying to scroll down the page to make the button visible on the page and then try to emulate a click on it. I am using the following code:
browser.executeScript('window.scrollTo(0, 200);').then(function() {
element.all(by.css('.item.item-complex')).get(9).click();
expect(browser.getTitle()).toEqual('Vegeta The Prince');
});
But scrolling doesn't happen with the above code. Please, help!
I am using Google Chrome.
+3
source to share
2 answers
I solved this problem using
window.scrollTo(x, y)
code:
var elm = element.all(by.css('.item.item-complex')).get(9);
elm.getLocation()
.then(function (location) {
return browser.executeScript('window.scrollTo(' + location.x + ', ' + location.y + ');')
})
.then(function () {
return elm.click();
})
})
+2
source to share