I am writing a program where I need to pass argument to my JavaScript function. How do I pass argument to the same?

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please log in or register.

1 Answer

answered by (171 points)
0 votes

You just need to cast the results to String:

JavaScriptExecutor js = (JavaScriptExecutor) driver;
String test = (String) js.executeScript("return arguments[0];", "element");

Hope that helps!