Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I execute JS command using my chromedriver, inside a Java code?

I would like to ask you how can I scroll into a web page by using a JS command. Though, I want this JS command inside a Java code-block. For the above purpose let me tell you that I also use Selenium framework. Is it possible?

The purpose is to do so by using Selenium and Java. I don't care about the general usage of JavascriptExecutor. I want their combination for SCROLL functionality!

like image 248
mukesh.maki Avatar asked Oct 28 '25 18:10

mukesh.maki


1 Answers

If I understand you correctly you are trying to scroll the page inside your selenium code. You can try something like this.

WebDriver driver = new ChromeDriver();

JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("window.scrollBy(0,1000)"); //Scroll vertically down by 1000 pixels

Let us know how this works for you.

like image 156
Sajja Pyakurel Avatar answered Oct 30 '25 07:10

Sajja Pyakurel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!