I'm currently trying to scroll a vertical scroll-bar without scrolling the whole page, I want it to implement javascript.
here is the code I'm using with:
IWebDriver driver = new FirefoxDriver();
driver.Navigate().GoToUrl("http://www.w3schools.com/html/default.asp");
Actions actions = new Actions(driver);
actions.MoveToElement(driver.FindElement(By.Id("leftmenuinnerinner"))).MoveToElement(driver.FindElement(By.Id("leftmenuinner"))).Build().Perform();
for (int i =0;i <= 1000; i++)
{
((IJavaScriptExecutor)driver).ExecuteScript("window.scrollBy(0,10)");
System.Threading.Thread.Sleep(10);
}
with this code the whole page starts scrolling and not the scroll bar. so any ideas on how to achieve that?
The below one worked for me.The element can be a element until which you want to scroll. WebElement element = driver.findElement(By.id("yourelement")); JavascriptExecutor jse = (JavascriptExecutor) driver; jse.executeScript("arguments[0].scrollIntoView();", element);
or you can try the below one.
findElement(By.xpath("yourelement").sendKeys(Keys.SPACE);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.