Can anybody please help me out to automate scroll down functionality with WebDriver using Java?
In my case, For yahoo mail "Sign In"
is getting displayed (visible) once I scroll down the mouse vertically.
Can anybody please help me out to automate scroll down functionality with WebDriver using Java?
In my case, For yahoo mail "Sign In"
is getting displayed (visible) once I scroll down the mouse vertically.
You can scroll down vertically by using the following code:
((JavascriptExecutor) driver).executeScript("scroll(0,250);");
Similarly, it is also possible to scroll up by changing y coordinate as negative:
((JavascriptExecutor) driver).executeScript("scroll(0, -250);");
You can also use the following code: For scroll down:
((JavascriptExecutor) driver).executeScript("window.scrollBy(0,250)", "");
For scroll up:
((JavascriptExecutor) driver).executeScript("window.scrollBy(0, -250)", "");
Scrolling to an Element of a page:
((JavascriptExecutor)driver).executeScript("arguments[0].scrollIntoView();"
,webElement);
Scrolling up should be as below:
((JavascriptExecutor) driver).executeScript("scroll(0,-250);");
If you are not sure about the height of the page and you are gonna scroll down to the down part of the page you can find the main frame of that page and use following code to scroll down without using scroll or scrollBy
scr1 = driver.find_element_by_xpath('xpath')
driver.execute_script("arguments[0].scrollTop = arguments[0].scrollHeight", scr1)
This will automatically go to the far down of the page. You can see an example here.