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
saiy2k
source
to share
2 answers
When I run into problems like this, I go through:
var elm = element.all(by.css('.item.item-complex')).get(9);
browser.executeScript("arguments[0].scrollIntoView();", elm.getWebElement());
elm.click();
+4
alecxe
source
to share
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
O. Strilchuk
source
to share