How to scroll a div

1,822 views
Skip to first unread message

Rita

unread,
Oct 26, 2016, 12:54:03 PM10/26/16
to NightwatchJs
Hi Everyone,


I need to scroll a div to make the button visible so nightwatch.js can click it.

I tried;

 .moveToElement('.load-more-btn',20,20)
 
also 


.execute(function () {
      windown
.scrollBy(0,100000);
},[])

but both didn´t work.

Can someone give me a hand on this?
Thanks in advance,
Rita

Sanja p

unread,
Oct 27, 2016, 3:21:36 AM10/27/16
to nightw...@googlegroups.com
Hi Rita, 

Have you tried this  
.execute('scrollTo(0,3000)')
This used to work for me. 


--
You received this message because you are subscribed to the Google Groups "NightwatchJs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nightwatchjs+unsubscribe@googlegroups.com.
To post to this group, send email to nightw...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nightwatchjs/8674c466-3da6-48ff-a3a2-005b0bf522d5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Rita

unread,
Oct 27, 2016, 9:57:12 AM10/27/16
to NightwatchJs
Hi MakS,

Not working either.


quinta-feira, 27 de Outubro de 2016 às 08:21:36 UTC+1, MakS escreveu:
Hi Rita, 

Have you tried this  
.execute('scrollTo(0,3000)')
This used to work for me. 

On 26 October 2016 at 18:54, Rita <rita.bra...@gmail.com> wrote:
Hi Everyone,


I need to scroll a div to make the button visible so nightwatch.js can click it.

I tried;

 .moveToElement('.load-more-btn',20,20)
 
also 


.execute(function () {
      windown
.scrollBy(0,100000);
},[])

but both didn´t work.

Can someone give me a hand on this?
Thanks in advance,
Rita

--
You received this message because you are subscribed to the Google Groups "NightwatchJs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nightwatchjs...@googlegroups.com.

Sanja p

unread,
Oct 27, 2016, 10:21:11 AM10/27/16
to nightw...@googlegroups.com
Are you receiving errors, or it is just not scrolling ? 

To unsubscribe from this group and stop receiving emails from it, send an email to nightwatchjs+unsubscribe@googlegroups.com.

To post to this group, send email to nightw...@googlegroups.com.

Rita

unread,
Oct 28, 2016, 4:31:02 AM10/28/16
to NightwatchJs
No errors and it skips to next action.

Putri Perdani

unread,
Nov 10, 2016, 4:38:42 PM11/10/16
to NightwatchJs
I wish this might helps

this.client.api.execute('scrollTo(0,300)');
this.waitForElementVisible('.load-more-btn', 5000);
this.click('.load-more-btn');

Derrick S

unread,
Dec 2, 2016, 6:06:09 PM12/2/16
to NightwatchJs
You shouldn't need to scroll to click the button, is the div in an iframe?

Trevor McCauley

unread,
Dec 4, 2016, 9:23:36 AM12/4/16
to NightwatchJs
I think everyone is missing the key point that its a div that needs to be scrolled, not the window.  To scroll a div, set its scrollTop/scrollLeft.  Only the window has the [global] methods scrollTo and scrollBy used to scroll the window itself.

browser.execute(function (selector, scrollX, scrollY) {

   
var elem = document.querySelector(selector);
    elem
.scrollLeft = scrollX;
    elem
.scrollTop = scrollY;

}, ['#element-to-scroll', 20, 20]);
Reply all
Reply to author
Forward
0 new messages