Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

JavascriptExecutor for scrolling does not work with selenium

  1. This what I have tried

    ‘Thread.sleep(3000);
    JavascriptExecutor js3 = (JavascriptExecutor) driver;
    js3.executeScript("window.scrollBy(0,500)", "");’

  2. But the page does not scroll down, is there perhaps another way of scroll down on a form, however when I try the above the form wont scroll so I am not able to get to the below element.

    MEDevel.com: Open-source for Healthcare and Education

    Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

    Visit Medevel

I want to scroll down to this element on the form.

'<div class="ant-select-selection__rendered" style=""><div unselectable="on" class="ant-select-selection__placeholder" style="display: none; user-select: none;">Select...</div><div title="" class="ant-select-selection-selected-value" style="display: block; opacity: 1;"></div></div>'

>Solution :

You can try the below way. I extracted the locator from your given html make sure its unique.

WebElement element = driver.findElement(By.cssSelector("div.ant-select-selection__rendered"));
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("arguments[0].scrollIntoView(true);", element);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading