Indranil
Indranil

Reputation: 2723

What is the use of "arguments[0]" when implementing javascriptexecutor?

I have implemented successfully JavascriptExecutor but I want to know why we take this array "arguments[0]"?

Here is the code below:

 IJavaScriptExecutor executor = (IJavaScriptExecutor)driver;
 executor.ExecuteScript("arguments[0].click();", driver.FindElement(locator));

Upvotes: 2

Views: 5432

Answers (2)

Mesut GUNES
Mesut GUNES

Reputation: 7411

Check the definition from Selenium ExecuteScript page

The arguments will be made available to the JavaScript via the "arguments" magic variable, as if the function were called via "Function.apply"

and the returning value of executeScript is:

Returns: One of Boolean, Long, String, List or WebElement. Or null.

which means that returning object is a list and you can interact with by arguments[0] magic variable.

Upvotes: 2

Nick Vanderhoven
Nick Vanderhoven

Reputation: 3093

It is a reference to the arguments you pass in. In this case the index is 0 because you're passing in the element reference as the 0th argument in the executeScript call (the parameter after the String containing the script).

Upvotes: 1

Related Questions