Silk Mobile

Table of Contents (Homepage)

HybridRunJavaScript

HybridRunJavascript(WebViewLocator , Index, Script)

images/images/os-icons/os_ios_150x150.png

images/images/os-icons/os_android_150x150.png

images/images/os-icons/os_windows_150x150.png

Description

Run Javascript in a WebView .

Parameters

  • WebViewLocator - WebView locator string like id=web or empty for the first WebView in page

  • Index - Element index

  • Script - Javascript (if you would like the command to return a value - just enter result=<javascript> )

Usage

Scenario: In the following example I will save the web page cookies names into a string.

Command usage: This command is useful for all special cases where standard Silk Mobile commands fail to work. In addition, by using this command, the user can access element and API that are not accessible in any other way.

Parameters:

  • WebViewLocator - WebView locator string like id=web or empty for the first WebView in page - will be Empty

  • Index - Element index - will be set to 0

  • Script - Javascript (if you would like the command to return a value - just enter result=<javascript>) - will be set to var result = document.cookie;

Code Examples

Java Example
String str0 = client.hybridRunJavascript("", 0, "var result = document.cookie;");
C# Example
String str0 = client.hybridRunJavascript("", 0, "var result = document.cookie;");
VBScript Example
str0 = client.HybridRunJavascript ( "", 0, "var result = document.cookie;" )
Report
Python Example
var0 = self.client.hybridRunJavascript("", 0, "var result = document.cookie;")
Perl Example
my $str0 = $client->hybridRunJavascript("", 0, "var result = document.cookie;");