I tried scroll(x,y) using javascript in Internet Explorer 10 . But, it did not work when I tried executing the script for a website. What is the equivalent for the same in IE ? It's a part of a Java Selenium test. I need to scroll in the page. So, I do that by executing a javascript code by using javascript executor.
for(int i=0;i<X;i+=Y)
String cmd = "window.scrollTo(0,"+i+")";
((JavascriptExecutor) driver).executeScript(cmd);
I use the above code in my test to scroll the page. But, in Internet Explorer IE10 it doesn't work.
I tried scroll(x,y) using javascript in Internet Explorer 10 . But, it did not work when I tried executing the script for a website. What is the equivalent for the same in IE ? It's a part of a Java Selenium test. I need to scroll in the page. So, I do that by executing a javascript code by using javascript executor.
for(int i=0;i<X;i+=Y)
String cmd = "window.scrollTo(0,"+i+")";
((JavascriptExecutor) driver).executeScript(cmd);
I use the above code in my test to scroll the page. But, in Internet Explorer IE10 it doesn't work.
Share Improve this question edited May 23, 2014 at 14:10 anirudh_raja asked May 23, 2014 at 13:56 anirudh_rajaanirudh_raja 3792 gold badges9 silver badges20 bronze badges 05 Answers
Reset to default 2The correct syntax would be window.scrollTo(xpos,ypos)
. This works in all major browsers, read about the function here.
why don't you try to scrollIntoView
the element like this
JavascriptExecutor jse=(JavascriptExecutor)driver;
jse.executeScript("document.getElementById(<id>).scrollIntoView(true)");
Faced similar issue. This works for me as an alternative for window.scrollTo
JS method in all browsers.
I had the same issue, but with IE 9.
I found that
executeScript("window.scrollTo(0,100)")
did not work, but
executeScript("window.scrollTo(0,100);")
did work. Note the ";" at the end of the executed mand.
Apparently there are issues with JavascriptExecutor in certain versions of IE10. Here provides a possible workaround but I have not tried it myself.
I am using below method for scrolling in case of Internet explorer (where element is the reference of WebElement, which needs to be scrolled to center of screen):
((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView(true);", element);
((JavascriptExecutor) driver).executeScript("window.scrollBy(0,-300)", "");
For other browsers, I am using:
((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView({block: \"center\"});", element);
Both of these will scroll the element to center of screen.
Do not forget to replace the desired locator instead of element.