// Java code desktop.<BrowserWindow> find("//BrowserWindow") .executeJavaScript("function foo() { alert('Silk Test'); }"); desktop.<BrowserWindow> find("//BrowserWindow") .executeJavaScript("foo();");
When replaying tests on Google Chrome, the scripts are not executed in the global context (window), but in a closure. Everything is executed within a function. The first ExecuteJavaScript call in the previous code sample will not work with Google Chrome, because the function foo is only available as long as the ExecuteJavaScript call lasts.
// Java code desktop.<BrowserWindow> find("//BrowserWindow") .executeJavaScript("window.foo = function() { alert('Silk Test'); }"); desktop.<BrowserWindow> find("//BrowserWindow") .executeJavaScript("window.foo();");
The previous code samples will work in Silk4J. The code for the other Silk Test clients is similar. For additional information, refer to the documentation of the ExecuteJavaScript method in the Help of your Silk Test client.