1

I tried

((JavascriptExecutor) driver).executeScript("windows.scrollBy(0,500)");

And

((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView();", element);

And

WebElement lastElement = driver.findElement(By.xpath("value of locator"));
int y = lastElement.getLocation().getY();
JavascriptExecutor js = (JavascriptExecutor)driver;
js.executeScript("window.scrollTo(0,"+y+")");
Thread.sleep(3000);

My window's scroll bar is moving down but I want to scroll my application's scroll bar. enter image description here

As in the attached image after clicking o settings it is opening further options & I have to scroll to see below options

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Sneha Shinde
  • 366
  • 1
  • 7
  • Possible duplicate of [Scroll Element into View with Selenium](https://stackoverflow.com/questions/3401343/scroll-element-into-view-with-selenium) – Boaz Jul 06 '18 at 08:36

2 Answers2

1

As per your code trials I think you were pretty close. You need to induce WebDriverWait for the desired element to be visible first and then use executeScript() method to scrollIntoView as follows:

WebElement lastElement = new WebDriverWait(driver, 20).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("xpath_of_the_desired_element"))).click();
((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView(true);",element);
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
0

It's how i scroll to an element of my DOM ( with jquery, tell me if you need vanilla ) :

$('#elementToScroll').animate({
            scrollTop: $("#scrollToThisElement").offset().top - $(window).height() / 2
 }, 0);

This code will center verticaly the .scrollToThisElement