executeScript() method for scrolling throws error as null cannot create object using Selenium Java

300 Views Asked by At

For scrolling through a section, I wrote below code:

JavaScriptExecutor js= (JavaScriptExecutor) driver;
js.executeScript (scroll code);

but here executeSctipt method is autosuggested like:

js.executeScript(null,args) 

and it throw error as null cannot create object. The actual argument (scroll code) is working as expected in the console.

It should be displayed as:

js.executeScript(arg0,arg1);
1

There are 1 best solutions below

0
On

Using the following Eclipse version:

Version: 2022-06 (4.24.0)
Build id: 20220609-1112

The perfect suggestions are observed:

executeScript

Though selecting the suggested option defaults to null and args but the tooltip still continues to suggest the actual argument types.

executeScriptNULL

You can use the executeScript() method accordingly:

((JavascriptExecutor)driver).executeScript("return arguments[0].scrollIntoView(true)", webElement);

Refrences

You can find a couple of relevant detailed discussions in: