How to scroll down in DIV?

In my application a dynamic grid gets loaded in DIV tag once I login to the application.

I need to first scroll down in the dynamic table and then identify the element and proceed.

I have tried the below code:


js.executeScript(“arguments[0].scrollTop = arguments[1];”,

getDriver().findElement(By.xpath(“.//*[@id=’dgrid’]”)), 100);

But did not work.

Please help.

SD Train Asked on June 14, 2016 in Selenium WebDriver.
Add Comment
2 Answer(s)

WebDriver driver = new ChromeDriver();


WebElement scrollElement = driver.findElement(By.xpath(“//*[@id=’example_wrapper’]/div[2]/div[2]”));

JavascriptExecutor executor = (JavascriptExecutor) driver;

int x = 1;
while(x < 4000)
int scrollD = (x % 2 == 0) ? (-1 * x) : x;
executor.executeScript(“arguments[0].scrollTop =” + scrollD, scrollElement);
x = x + 40;



Virender Singh Professor Answered on June 17, 2016.

Thanks Virender,

I need to scroll till the bottom of the grid and then find the element. I cannot go to the specific element as the number of rows of data keep changing.

Suppose there are 135 rows of data in the dynamic grid the XPATH for the last row is as shown below:


And if there are 1600 rows of data in the dynamic grid the XPATH for the last row is as shown below :


In my test case I need to come to end of the table by scrolling down the dynamic grid.

Is there anyway I can scroll till the end of table ??


on June 17, 2016.
Add Comment


The length of the grid /dynamic table is calculated using the height and width of the html page.
Example  – (window).height() – offset()) – 65  This gives the grid  area.

Can this be achieved using Javascript Executor?

This is the jQuery code


SD Train Answered on July 8, 2016.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.