Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scroll down to an element with protractor

I have an element on the page that I'm testing that I have to scroll down to be visible. When I execute my test, I get Element is not clickable at point (94, 188) for example.

I tried the following:

dvr.executeScript('window.scrollTo(0,250);');

But it didn't work. Does anyone know how this works?

like image 348
andrepm Avatar asked Nov 19 '14 18:11

andrepm


4 Answers

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..

like image 78
Rahul Reddy Avatar answered Nov 20 '22 01:11

Rahul Reddy


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(...);
});
like image 27
Junior Ales Avatar answered Nov 20 '22 00:11

Junior Ales


'use strict';

/**
 * Vertically scroll top-left corner of the given element (y-direction) into viewport.
 * @param scrollToElement element to be scrolled into visible area
 */
function scrollTo(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.

like image 5
James Lawson Avatar answered Nov 20 '22 02:11

James Lawson


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

like image 2
rajana sekhar Avatar answered Nov 20 '22 02:11

rajana sekhar