Skip to content

WebView.ExecuteScript

method · WebView · cAlgo.API

DesktopCLICloud

Executes JavaScript code from the javaScript parameter in the current top level document rendered in the WebView and returns the result. You can only use this method after control is fully loaded and navigation is completed.

Environment behaviour

CLI — not supported. Accepted without error but never displayed, so control events such as Click are never raised.

Cloud — not supported. Accepted without error but never displayed, so control events such as Click are never raised.

Definition

public ExecuteScriptResult ExecuteScript(string javaScript)
webView.ExecuteScript(javaScript: str) -> ExecuteScriptResult

Parameters

Name C# type Python type Description
javaScript string str JavaScript code

Returns ExecuteScriptResult — ExecuteScriptResult

Examples

var webView = new WebView { Width = 300, Height = 100 };
webView.NavigateToStringAsync("<html><body>Spread monitor</body></html>");
webView.NavigationCompleted += args =>
{
    var result = webView.ExecuteScript("document.title = 'EURUSD'; document.body.innerText");
    if (result != null && result.IsSuccessful)
        Print("Script result: {0}", result.Json);
};
Chart.AddControl(webView);
def on_start(self):
    self.webView = WebView()
    self.webView.NavigateToStringAsync("<html><body>Spread monitor</body></html>")
    self.webView.NavigationCompleted += self.on_navigation_completed
    api.Chart.AddControl(self.webView)

def on_navigation_completed(self, args):
    result = self.webView.ExecuteScript("document.body.innerText")
    if result is not None and result.IsSuccessful:
        api.Print(f"Script result: {result.Json}")