<T>
executePhantomJS(script, args)code »
Executes a PhantomJS fragment. This method is similar to #executeScript
, except it exposes the PhantomJS API to the injected script.
The injected script will execute in the context of PhantomJS's
page
variable. If a page has not been loaded before calling this
method, one will be created.
Be sure to wrap callback definitions in a try/catch block, as failures
may cause future WebDriver calls to fail.
Certain callbacks are used by GhostDriver (the PhantomJS WebDriver
implementation) and overriding these may cause the script to fail. It is
recommended that you check for existing callbacks before defining your own.
As with #executeScript
, the injected script may be defined as a string for an anonymous function body (e.g. "return 123;"), or as a function. If a function is provided, it will be decompiled to its original source. Note that injecting functions is provided as a convenience to simplify defining complex scripts. Care must be taken that the function only references variables that will be defined in the page's scope and that the function does not override Function.prototype.toString
(overriding toString() will interfere with how the function is decompiled.
Parameters
- script
(string|Function)
The script to execute.
- args
?