Scroll window horizontally with selenium in Java

110 views
Skip to first unread message

derek...@gmail.com

unread,
May 2, 2016, 2:48:07 PM5/2/16
to Selenium Users
Is it possible to scroll the window horizontally by a small margin using selenium code ?

ericb...@gmail.com

unread,
May 3, 2016, 5:23:02 AM5/3/16
to Selenium Users
You could do it with the javascript executor.

jsExecutor.executeScript('scroll(1000, 0)');

There's a similar question and answer here: http://forum.testproject.io/index.php?topic=55.0

anemuday

unread,
May 3, 2016, 7:48:28 AM5/3/16
to Selenium Users
Hi Derek,

Below is the line of code that will scroll 500 pixels from top.

((JavascriptExecutor) driver).executeScript("window.scrollTo(0, 500)"); 0 is x-coordinate and 500 is y-coordinates from top.

Let us know if it works out.

Thanks,
Uday

anemuday

unread,
May 3, 2016, 7:58:03 AM5/3/16
to Selenium Users
Sorry,

You wanted scrolling horizontal right? so you can change x-coordinate to 1000 and y as 0

((JavascriptExecutor) driver).executeScript("window.scrollTo(1000, 0)");

divya

unread,
Jun 19, 2017, 4:27:20 AM6/19/17
to Selenium Users
Hi ,

I am trying to scroll the page down using java Script Executor and the code is as below :


But it doesn't Execute the script Any help is Appreciated.i am Also not sure about the pixel number to be given?



((JavascriptExecutor)driver).executeScript("scroll(0,2000)");.

anemuday

unread,
Jun 20, 2017, 3:08:42 AM6/20/17
to Selenium Users
Divya,

Your screen resolution may not have 2000 y coordinate. Generally x,y coordinates are like 1024 * 768 etc....

Try using scroll with 1000(y-coordinate) or 500 like that.
((JavascriptExecutor)driver).executeScript("scroll(0,1000)");

srividya yanamala

unread,
Jul 16, 2017, 8:23:09 AM7/16/17
to seleniu...@googlegroups.com
Hi ,

I am trying to click on an element and it is located below the page hence using scroll to move it down. the element is getting highlighted but it is not clicked.

1. Tried adding wait and also tried using Actions double click and the is displayed for element says true and I have added enough wait time also .

the xpath for the  same is:
//div[@id='overviewtab_1']//div[@class='row']/div//button[@class='btn btn-primary pull-right btn-sm']

Actually the xpath has many divs like .//*[@id='overviewtab_1']/div/div/div/div/div[2]/div/div/div/div[1]/div/div/button so modified it .

The element is highlighted when run the script but does not click . Can some one help me please.


Thanks,
Srividya.






--
You received this message because you are subscribed to a topic in the Google Groups "Selenium Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/selenium-users/yg-UUagzAT8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to selenium-users+unsubscribe@googlegroups.com.
To post to this group, send email to selenium-users@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/7cc1c38d-8507-44ef-aac2-9507313c07be%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages