0

I need to automate scrolling down using the scroll bar. This is what the scroll bar looks like. This is the html code of the scroll bar:

<div class="z-biglistbox-wscroll-vertical">
    <div class="z-biglistbox-wscroll-drag" style="top: 132.253px;">
        <div class="z-biglistbox-wscroll-home" title="Home"></div>
        <div class="z-biglistbox-wscroll-up" title="Previous"></div>
        <div class="z-biglistbox-wscroll-down" title="Next"></div>
        <div class="z-biglistbox-wscroll-end" title="End"></div>
    </div>
</div>

I think of maybe clicking the "Next" button of the scroll bar but my code's not working. I did something like the following:

((JavascriptExecutor)driver).executeScript("arguments[0].click();", scroll_down);

.

WebElement scroll_down = driver.findElement(By.cssSelector(".z-biglistbox-wscroll-down"));
scroll_down.click();

Neither of the two worked. Can anyone give me an idea how to do it?

UPDATE: This problem was already solved. Refer to alecxe's answer in this link for the solution that worked for me.

Andrea
  • 41
  • 2
  • 6

3 Answers3

0

You can use javascriptexecutor directly for scrolling. Below code might give you some idea.

Case 1: To scroll upto a certain element so that the expected element will be visible

JavascriptExecutor je = (JavascriptExecutor) driver;

//Identify the WebElement which will appear after scrolling down
WebElement element = driver.findElement(By.xpath(".//*[@id='mCSB_3_container']/p[3]"));

// now execute query which actually will scroll until that element is not appeared on page.
je.executeScript("arguments[0].scrollIntoView(true);",element);

Case 2: To scroll upto a certain element

((JavascriptExecutor)driver).executeScript("scroll(0,400)");

Hope this helps you. Thanks.

santhosh kumar
  • 1,981
  • 1
  • 9
  • 28
  • Thank you but this didn't work for me. The problem is fixed tho, refer to the update on the question. – Andrea Jul 07 '17 at 03:04
0
WebElement element = driver.findElement(By.className("z-biglistbox-wscroll-down"));
element.click();

You can use this but it will click only once in the scroll down element.

piet.t
  • 11,718
  • 21
  • 43
  • 52
Sudha Velan
  • 633
  • 8
  • 24
  • It's not working. It's not clicking the down arrow even once. – Andrea Jul 06 '17 at 05:59
  • `WebElement element = driver.findElement(By.xpath(".//div[@class='z-biglistbox-wscroll-vertical']//div[@class='z-biglistbox-wscroll-down']")); element.click();` try this know.Is there any iframe there in the dom? – Sudha Velan Jul 06 '17 at 06:28
0

Try below code for scrolling your window to bottom :

WebDriver driver = new FirefoxDriver();
JavascriptExecutor jse = (JavascriptExecutor)driver;

JavascriptExecutor jsx = (JavascriptExecutor) driver;
jsx.executeScript("window.scrollBy(0,500)", "");
whatsinthename
  • 1,828
  • 20
  • 59
  • Thank you but this didn't work for me. My problem is fixed tho, refer to the update on the question. – Andrea Jul 07 '17 at 03:04