Browser execute (FR)

Perfecto Command

mobile:browser:execute

Purpose

Executes a JavaScript script on the device browser application. Supported for Chrome, Safari, and instrumented hybrid apps.

Parameters

Name Type Possible Values Description
script String The JavaScript code, encoded as a String, to execute.
repositoryFile Multimedia The full repository path, including directory and file name, where to locate the JavaScript script.
Example -
PRIVATE:dir1/dir2/myJavaScript.js
Click browse and navigate to the file.
timeout Integer

The time, in seconds, to wait for the page to be loaded in order to execute the JavaScript code. (Default: 30 seconds)

Note: The JavaScript code cannot be executed while the page is in loading state.

webView Integer For hybrid applications - The index number of the web view element.

Return Value

None

Exceptions

None

Examples

Copy

Java sample

//declare the Map for script parameters
Map<String, Object> params = new HashMap<>();
   
params.put("repositoryFile", "PRIVATE:scripts/myJscript.js");
params.put("timeout", "35");
driver.executeScript("mobile:browser:execute", params)
Copy

C# sample

//declare the Map for script parameters
Dictionary<String, Object> pars = new Dictionary<String, Object>();

pars.Add("repositoryFile", "PRIVATE:scripts/myJscript.js"); 
pars.Add("timeout", "35");
driver.ExecuteScript("mobile:browser:execute", pars);