This class provides extension methods from the IWebDriver interface for easier JavaScript execution on the WebDriver.
ExecuteScript
Executes JavaScript in the context of the currently selected frame or window. If the generic type is omitted than this method will not return any result.
driver.ExecuteScript("myJavaScriptMethod();");
Executes JavaScript in the context of the currently selected frame or window. If the generic type is given than this method will return the result from the JavaScript code. Please note that the result is cast following the same rules that Selenium has for JavaScript results:
For an HTML element, this method returns a IWebElement,
For a number, a long is returned,
For a boolean, a bool is returned,
For all other cases a string is returned,
For an array, the first element is checked, and the attempt is made to return a List<T> of that type, following the rules above. Nested lists are not supported.
var result = driver.ExecuteScript<string>("return myJavaScriptMethod();");
LoadJQuery
When JQuerySelector is used the library will detect if the tested page contains the loaded jQuery library and if jQuery is not present, the library will load it before running the selector. jQuery will be loaded from a CDN from this url:
In some cases there may be a need to load an alternative version of the library, or to load the library from a different source and for this purpose the LoadJQuery method is available.
Load a different version of the jQuery library from CDN.
Specify a timeout for jQuery library load. The timeout can be specified with both version and URL overrides. The default value for the timeout is 10 seconds.
When SizzleSelector is used the library will detect if the tested page contains the loaded Sizzle library and if Sizzle is not present, the library will load it before running the selector. Sizzle will be loaded from a CDN from this url:
In some cases there may be a need to load an alternative version of the library, or to load the library from a different source and for this purpose the LoadSizzle method is available.
Load a different version of the Sizzle library from CDN.
Specify a timeout for Sizzle library load. The timeout can be specified with both version and URL overrides. The default value for the timeout is 10 seconds.