Reputation: 2723
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
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
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