I have written the following code in Selenium 1 (a.k.a Selenium RC) for page scrolling using java:
selenium.getEval("scrollBy(0, 250)");
What is the equivalent code in Selenium 2 (WebDriver)?
I have written the following code in Selenium 1 (a.k.a Selenium RC) for page scrolling using java:
selenium.getEval("scrollBy(0, 250)");
What is the equivalent code in Selenium 2 (WebDriver)?
For Scroll down:
OR, you can do as follows:
For Scroll up:
You should add a scroll to the page to select all elements using
Selenium.executeScript("window.scrollBy(0,450)", "")
.If you have a large list, add the scroll several times through the execution. Note the scroll only go to a certain point in the page for example (0,450).
This may not be an exact answer to your question (in terms of WebDriver), but I've found that the
java.awt
library is more stable thanselenium.Keys
. So, a page down action using the former will be:Try this
There are many ways to scroll up and down in Selenium Webdriver I always use Java Script to do the same.
Below is the code which always works for me if I want to scroll up or down
You can get full code from here Scroll Page in Selenium
If you want to scroll for a element then below piece of code will work for you.
You will get the full doc here Scroll for specific Element
Scroll down:
Scroll up: