public class PhantomJSDriver
extends org.openqa.selenium.remote.RemoteWebDriver
implements org.openqa.selenium.TakesScreenshot
WebDriver implementation that controls a PhantomJS running in Remote WebDriver mode.
This class is provided as a convenience for easily testing PhantomJS.
The control server which each instance communicates with will live and die with the instance.
The Driver requires to optionally set some Capabilities or Environment Variables:
PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTYPhantomJSDriverService.PHANTOMJS_GHOSTDRIVER_PATH_PROPERTYPhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY is required only if the executable
phantomjs is not available through the $PATH environment variable:
you can provide it either via the Capabilities construction parameter object,
or via System Property.
PhantomJSDriverService.PHANTOMJS_GHOSTDRIVER_PATH_PROPERTY is optional in case you want to use a specific
version of GhostDriver (i.e. during development of GhostDriver).
You can provide it either via the Capabilities construction parameter object,
or via System Property.
Instead, if you have a PhantomJS WebDriver process already running, you can instead use RemoteWebDriver.RemoteWebDriver(java.net.URL, org.openqa.selenium.Capabilities) to delegate the
execution of your WebDriver/Selenium scripts to it. Of course, in that case you will than be in
charge to control the life-cycle of the PhantomJS process.
NOTE: PhantomJS Remote WebDriver mode is implemented via
GhostDriver.
It's a separate project that, at every stable release, is merged into PhantomJS.
If interested in developing (contributing to) GhostDriver, it's possible to run PhantomJS and pass GhostDriver as
a script.
NOTE: The design of this class is heavily inspired by ChromeDriver.org.openqa.selenium.remote.RemoteWebDriver.RemoteTargetLocator, org.openqa.selenium.remote.RemoteWebDriver.RemoteWebDriverOptions, org.openqa.selenium.remote.RemoteWebDriver.Whenorg.openqa.selenium.WebDriver.ImeHandler, org.openqa.selenium.WebDriver.Navigation, org.openqa.selenium.WebDriver.Options, org.openqa.selenium.WebDriver.TargetLocator, org.openqa.selenium.WebDriver.Timeouts, org.openqa.selenium.WebDriver.Window| Constructor and Description |
|---|
PhantomJSDriver()
Creates a new PhantomJSDriver instance.
|
PhantomJSDriver(org.openqa.selenium.Capabilities desiredCapabilities)
Creates a new PhantomJSDriver instance.
|
PhantomJSDriver(PhantomJSDriverService service,
org.openqa.selenium.Capabilities desiredCapabilities)
Creates a new PhantomJSDriver instance.
|
| Modifier and Type | Method and Description |
|---|---|
java.lang.Object |
executePhantomJS(java.lang.String script,
java.lang.Object... args)
Execute a PhantomJS fragment.
|
protected static java.util.Map<java.lang.String,org.openqa.selenium.remote.CommandInfo> |
getCustomCommands() |
<X> X |
getScreenshotAs(org.openqa.selenium.OutputType<X> target)
Take screenshot of the current window.
|
close, execute, execute, executeAsyncScript, executeScript, findElement, findElement, findElementByClassName, findElementByCssSelector, findElementById, findElementByLinkText, findElementByName, findElementByPartialLinkText, findElementByTagName, findElementByXPath, findElements, findElements, findElementsByClassName, findElementsByCssSelector, findElementsById, findElementsByLinkText, findElementsByName, findElementsByPartialLinkText, findElementsByTagName, findElementsByXPath, get, getCapabilities, getCommandExecutor, getCurrentUrl, getElementConverter, getErrorHandler, getExecuteMethod, getFileDetector, getKeyboard, getMouse, getPageSource, getRemoteStatus, getSessionId, getTitle, getWindowHandle, getWindowHandles, log, manage, navigate, quit, setCommandExecutor, setElementConverter, setErrorHandler, setFileDetector, setFoundBy, setLogLevel, setSessionId, startClient, startSession, startSession, stopClient, switchTo, toStringpublic PhantomJSDriver()
for configuration details.public PhantomJSDriver(org.openqa.selenium.Capabilities desiredCapabilities)
desiredCapabilities - The capabilities required from PhantomJS/GhostDriver.for configuration details.public PhantomJSDriver(PhantomJSDriverService service, org.openqa.selenium.Capabilities desiredCapabilities)
service will be started along with the
driver, and shutdown upon calling RemoteWebDriver.quit().service - The service to use.desiredCapabilities - The capabilities required from PhantomJS/GhostDriver.public <X> X getScreenshotAs(org.openqa.selenium.OutputType<X> target)
throws org.openqa.selenium.WebDriverException
getScreenshotAs in interface org.openqa.selenium.TakesScreenshotgetScreenshotAs in class org.openqa.selenium.remote.RemoteWebDrivertarget - The target type/format of the Screenshotorg.openqa.selenium.WebDriverExceptionTakesScreenshot.getScreenshotAs(org.openqa.selenium.OutputType)public java.lang.Object executePhantomJS(java.lang.String script,
java.lang.Object... args)
script - The fragment of PhantomJS JavaScript to execute.args - List of arguments to pass to the function that the script is wrapped in.
These can accessed in the script as 'arguments[0]', 'arguments[1]',
'arguments[2]', etcprotected static java.util.Map<java.lang.String,org.openqa.selenium.remote.CommandInfo> getCustomCommands()