Gian Marco Te Gian Marco Te - 6 days ago 7
jQuery Question

C# Selenium how to scroll a scrollable div, not the entire webpage without using pageup/pgdn

I'm trying to scroll a div that loads rows everytime I reach the bottom of the scrollbar. Now I am doing this by "scrolling" the scrollbar of the div using PgUp and PgDn but I encountered a problem where a specific div is not accepting pgup/pgdown/home/end. How do I drag and drop the scrollbar using C# and Selenium?

This is my code for pgup and pgdn:

private void ScrollTable(int scrollcount, string pageDirection, string delay)
{
Actions actions = new Actions(DlkEnvironment.AutoDriver);
actions.MoveToElement(mTableElement);
for (int i = 1; i <= scrollcount; i++)
{
//if loading is not displayed/visible,
IsLoadingScreenIsDisplayed(delay);
//execute after waiting
switch (pageDirection.ToLower())
{
case "up":
actions.Click().SendKeys(Keys.PageUp).Perform();
break;
case "down":
actions.Click().SendKeys(Keys.PageDown).Perform();
break;
default:
throw new Exception("Invalid direction");
}
}
Thread.Sleep(1000);
}

Answer

Fixed using JavaScript, scrollTop function. use the scrollTop function to your element

Comments