Scroll Down To An Element With Protractor
Solution 1:
This seems so late to answer you.. But anyways,
The following code helped me to remove the Element is not clickable error.
var elm = element.all(by.css('.your-css-class')).get(9);
browser.executeScript("arguments[0].scrollIntoView();", elm.getWebElement());
elm.click();
Basically this allows you scroll into your view..
Solution 2:
The window.scrollTo(x,x)
solution didn't work for me. Specially when testing against ripple emulator.
I managed to make it work using scrollIntoView
method.
var scrollToScript = 'document.getElementById("ELEMENT ID").scrollIntoView();';
browser.driver.executeScript(scrollToScript).then(function() {
element(by.id('ELEMENT ID')).click();
expect(...);
});
Solution 3:
'use strict';
/**
* Vertically scroll top-left corner of the given element (y-direction) into viewport.
* @param scrollToElement element to be scrolled into visible area
*/functionscrollTo(scrollToElement) {
var wd = browser.driver;
return scrollToElement.getLocation().then(function (loc) {
return wd.executeScript('window.scrollTo(0,arguments[0]);', loc.y);
});
};
Usage:
scrollTo(element(by.css("div.someclass")));
Disclaimer: this code is from sg-protractor-tools's scroll.js
.
Code is licensed under the MIT license.
Solution 4:
i think this is helpful to you:
dvr.executeScript('window.scrollTo(94,188);').then(function() {
element(by.<<here your button locator>>).click();
})
your webdriver is unable to read that point (1254,21),the reason is your protractor browser unable to cover the full of page what do you want to test, then we give a command that browser is scroll to that point (1254,21), then perform the click operation
Solution 5:
I used the link that Bassem suggested and that works. The steps are as follows:
We will have to install sg-protractor-tools with the following command (Use Sudo if you do not have admin accesses):
npm install --save-dev sg-protractor-tools
The code then would look something like this (I tried this on wikipedia)
var sgpt = require('sg-protractor-tools'); it ('verify that scroll works', function () { browser.get('http://wikipedia.org'); browser.manage().window().setSize(1000, 1000); sgpt.scroll.scrollTo(element(by.linkText('Terms of Use'))); } );
Post a Comment for "Scroll Down To An Element With Protractor"