-1

Can someone please help me how to get this code working?

String mvt = "1500";

JavascriptExecutor js = (JavascriptExecutor)driver;
js.executeScript("window.scrollBy(0,mvt));

As you can see I want to use the number in mvt in the execution script. For now, I get the error:

syntax error, insert ";" to complete Statement
String literal is not properly closed by a double-quote

at UsingActionsClass.UsingActions.main(UsingActions.java:23)

So, what will be the proper syntax, please?

Thank you.

1

2 Answers 2

0

There are a couple issues. One is that you didn't close the quotes... that is what the error message is telling you. The second issue is that you aren't passing your mvt variable into the JS call. The corrected code is below.

JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("window.scrollBy(0, arguments[0])", mvt);
Sign up to request clarification or add additional context in comments.

1 Comment

can i use 2 or more arguments? for example: String mvt = "1500"; String mvt2 = "3500"; //Scroll down JavascriptExecutor js = (JavascriptExecutor)driver; js.executeScript("window.scrollBy(0, arguments[0])", mvt,mvt2); if possible what will be the proper syntax?
0

You need to close the the quotes of the JavaScript snippet, and then the parenthesis of the call:

js.executeScript("window.scrollBy(0, arguments[0]);", mvt);

2 Comments

You fixed one problem but mvt is undefined the way it's written.
You are correct. The script is starting now but it is not scrolling. Can you please tell me what is the proper way to define mvt?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.