public class JBrowserDriver
extends org.openqa.selenium.remote.RemoteWebDriver
See https://github.com/machinepublishers/jbrowserdriver#usage for basic usage info.
Licensed under the Apache License version 2.0.
org.openqa.selenium.remote.RemoteWebDriver.RemoteTargetLocator, org.openqa.selenium.remote.RemoteWebDriver.RemoteWebDriverOptions, org.openqa.selenium.remote.RemoteWebDriver.WhenWebDriver.ImeHandler, WebDriver.Navigation, WebDriver.Options, WebDriver.TargetLocator, WebDriver.Timeouts, WebDriver.Window| Constructor and Description |
|---|
JBrowserDriver()
Constructs a browser with default settings, UTC timezone, and no proxy.
|
JBrowserDriver(Capabilities capabilities)
Use
Settings.builder() ...buildCapabilities() to create settings to pass to this constructor. |
JBrowserDriver(Settings settings)
Use
Settings.builder() ...build() to create settings to pass to this constructor. |
| Modifier and Type | Method and Description |
|---|---|
File |
attachmentsDir() |
File |
cacheDir() |
void |
close()
Close the current window, quitting the browser if it's the last window currently open.
|
Object |
executeAsyncScript(String script,
Object... args)
Execute an asynchronous piece of JavaScript in the context of the currently selected frame or
window.
|
Object |
executeScript(String script,
Object... args)
Executes JavaScript in the context of the currently selected frame or window.
|
protected void |
finalize() |
WebElement |
findElement(By by)
Find the first
WebElement using the given method. |
WebElement |
findElementByClassName(String cssClass) |
WebElement |
findElementByCssSelector(String expr) |
WebElement |
findElementById(String id) |
WebElement |
findElementByLinkText(String text) |
WebElement |
findElementByName(String name) |
WebElement |
findElementByPartialLinkText(String text) |
WebElement |
findElementByTagName(String tagName) |
WebElement |
findElementByXPath(String expr) |
List<WebElement> |
findElements(By by)
Find all elements within the current page using the given mechanism.
|
List<WebElement> |
findElementsByClassName(String cssClass) |
List<WebElement> |
findElementsByCssSelector(String expr) |
List<WebElement> |
findElementsById(String id) |
List<WebElement> |
findElementsByLinkText(String text) |
List<WebElement> |
findElementsByName(String name) |
List<WebElement> |
findElementsByPartialLinkText(String text) |
List<WebElement> |
findElementsByTagName(String tagName) |
List<WebElement> |
findElementsByXPath(String expr) |
void |
get(String url)
Load a new web page in the current browser window.
|
Capabilities |
getCapabilities() |
org.openqa.selenium.remote.CommandExecutor |
getCommandExecutor() |
String |
getCurrentUrl()
Get a string representing the current URL that the browser is looking at.
|
org.openqa.selenium.remote.ErrorHandler |
getErrorHandler() |
org.openqa.selenium.remote.FileDetector |
getFileDetector() |
Keyboard |
getKeyboard() |
Mouse |
getMouse() |
String |
getPageSource()
Get the source of the last loaded page.
|
<X> X |
getScreenshotAs(OutputType<X> outputType)
Capture the screenshot and store it in the specified location.
|
org.openqa.selenium.remote.SessionId |
getSessionId() |
int |
getStatusCode() |
String |
getTitle()
The title of the current page.
|
String |
getWindowHandle()
Return an opaque handle to this window that uniquely identifies it within this driver instance.
|
Set<String> |
getWindowHandles()
Return a set of window handles which can be used to iterate over all open windows of this
WebDriver instance by passing them to
WebDriver.switchTo().WebDriver.Options.window() |
void |
init()
Optionally call this method if you want JavaFX initialized and the browser
window opened immediately.
|
static void |
initWorkThread() |
void |
kill() |
WebDriver.Options |
manage()
Gets the Option interface
|
File |
mediaDir() |
WebDriver.Navigation |
navigate()
An abstraction allowing the driver to access the browser's history and to navigate to a given
URL.
|
void |
pageWait()
Waits until requests are completed and idle for a certain
amount of time.
|
void |
quit()
Quits this driver, closing every associated window.
|
void |
reset()
Reset the state of the browser.
|
void |
reset(Capabilities capabilities)
Reset the state of the browser.
|
void |
reset(Settings settings)
Reset the state of the browser.
|
WebDriver.TargetLocator |
switchTo()
Send future commands to a different frame or window.
|
static List<String> |
test()
Run diagnostic tests.
|
execute, execute, findElement, findElements, getElementConverter, getExecuteMethod, getW3CStandardComplianceLevel, log, setCommandExecutor, setElementConverter, setErrorHandler, setFileDetector, setFoundBy, setLogLevel, setSessionId, startClient, startSession, startSession, stopClient, toStringpublic JBrowserDriver()
public JBrowserDriver(Capabilities capabilities)
Settings.builder() ...buildCapabilities() to create settings to pass to this constructor.
This constructor is mostly useful for Selenium Server itself to use.capabilities - public JBrowserDriver(Settings settings)
Settings.builder() ...build() to create settings to pass to this constructor.settings - public File attachmentsDir()
public File cacheDir()
public void close()
public Object executeAsyncScript(String script, Object... args)
synchronous JavaScript,
scripts executed with this method must explicitly signal they are finished by invoking the
provided callback. This callback is always injected into the executed function as the last
argument.
The first argument passed to the callback function will be used as the script's result. This value will be handled as follows:
The default timeout for a script to be executed is 0ms. In most cases, including the examples
below, one must set the script timeout
WebDriver.Timeouts.setScriptTimeout(long, java.util.concurrent.TimeUnit) beforehand
to a value sufficiently large enough.
Example #1: Performing a sleep in the browser under test.
long start = System.currentTimeMillis();
((JavascriptExecutor) driver).executeAsyncScript(
"window.setTimeout(arguments[arguments.length - 1], 500);");
System.out.println(
"Elapsed time: " + System.currentTimeMillis() - start);
Example #2: Synchronizing a test with an AJAX application:
WebElement composeButton = driver.findElement(By.id("compose-button"));
composeButton.click();
((JavascriptExecutor) driver).executeAsyncScript(
"var callback = arguments[arguments.length - 1];" +
"mailClient.getComposeWindowWidget().onload(callback);");
driver.switchTo().frame("composeWidget");
driver.findElement(By.id("to")).sendKeys("bog@example.com");
Example #3: Injecting a XMLHttpRequest and waiting for the result:
Object response = ((JavascriptExecutor) driver).executeAsyncScript(
"var callback = arguments[arguments.length - 1];" +
"var xhr = new XMLHttpRequest();" +
"xhr.open('GET', '/resource/data.json', true);" +
"xhr.onreadystatechange = function() {" +
" if (xhr.readyState == 4) {" +
" callback(xhr.responseText);" +
" }" +
"};" +
"xhr.send();");
JsonObject json = new JsonParser().parse((String) response);
assertEquals("cheese", json.get("food").getAsString());
Script arguments must be a number, a boolean, a String, WebElement, or a List of any combination of the above. An exception will be thrown if the arguments do not meet these criteria. The arguments will be made available to the JavaScript via the "arguments" variable.
executeAsyncScript in interface JavascriptExecutorexecuteAsyncScript in class org.openqa.selenium.remote.RemoteWebDriverscript - The JavaScript to execute.args - The arguments to the script. May be empty.WebDriver.Timeouts.setScriptTimeout(long, java.util.concurrent.TimeUnit)public Object executeScript(String script, Object... args)
Within the script, use document to refer to the current document. Note that local
variables will not be available once the script has finished executing, though global variables
will persist.
If the script has a return value (i.e. if the script contains a return statement),
then the following steps will be taken:
Arguments must be a number, a boolean, a String, WebElement, or a List of any combination of the above. An exception will be thrown if the arguments do not meet these criteria. The arguments will be made available to the JavaScript via the "arguments" magic variable, as if the function were called via "Function.apply"
executeScript in interface JavascriptExecutorexecuteScript in class org.openqa.selenium.remote.RemoteWebDriverscript - The JavaScript to executeargs - The arguments to the script. May be emptyprotected void finalize()
throws Throwable
public WebElement findElement(By by)
WebElement using the given method.
This method is affected by the 'implicit wait' times in force at the time of execution.
The findElement(..) invocation will return a matching row, or try again repeatedly until
the configured timeout is reached.
findElement should not be used to look for non-present elements, use WebDriver.findElements(By)
and assert zero length response instead.findElement in interface SearchContextfindElement in interface WebDriverfindElement in class org.openqa.selenium.remote.RemoteWebDriverby - The locating mechanismBy,
WebDriver.Timeoutspublic WebElement findElementByClassName(String cssClass)
findElementByClassName in interface FindsByClassNamefindElementByClassName in class org.openqa.selenium.remote.RemoteWebDriverpublic WebElement findElementByCssSelector(String expr)
findElementByCssSelector in interface FindsByCssSelectorfindElementByCssSelector in class org.openqa.selenium.remote.RemoteWebDriverpublic WebElement findElementById(String id)
findElementById in interface FindsByIdfindElementById in class org.openqa.selenium.remote.RemoteWebDriverpublic WebElement findElementByLinkText(String text)
findElementByLinkText in interface FindsByLinkTextfindElementByLinkText in class org.openqa.selenium.remote.RemoteWebDriverpublic WebElement findElementByName(String name)
findElementByName in interface FindsByNamefindElementByName in class org.openqa.selenium.remote.RemoteWebDriverpublic WebElement findElementByPartialLinkText(String text)
findElementByPartialLinkText in interface FindsByLinkTextfindElementByPartialLinkText in class org.openqa.selenium.remote.RemoteWebDriverpublic WebElement findElementByTagName(String tagName)
findElementByTagName in interface FindsByTagNamefindElementByTagName in class org.openqa.selenium.remote.RemoteWebDriverpublic WebElement findElementByXPath(String expr)
findElementByXPath in interface FindsByXPathfindElementByXPath in class org.openqa.selenium.remote.RemoteWebDriverpublic List<WebElement> findElements(By by)
findElements in interface SearchContextfindElements in interface WebDriverfindElements in class org.openqa.selenium.remote.RemoteWebDriverby - The locating mechanism to useWebElements, or an empty list if nothing matchesBy,
WebDriver.Timeoutspublic List<WebElement> findElementsByClassName(String cssClass)
findElementsByClassName in interface FindsByClassNamefindElementsByClassName in class org.openqa.selenium.remote.RemoteWebDriverpublic List<WebElement> findElementsByCssSelector(String expr)
findElementsByCssSelector in interface FindsByCssSelectorfindElementsByCssSelector in class org.openqa.selenium.remote.RemoteWebDriverpublic List<WebElement> findElementsById(String id)
findElementsById in interface FindsByIdfindElementsById in class org.openqa.selenium.remote.RemoteWebDriverpublic List<WebElement> findElementsByLinkText(String text)
findElementsByLinkText in interface FindsByLinkTextfindElementsByLinkText in class org.openqa.selenium.remote.RemoteWebDriverpublic List<WebElement> findElementsByName(String name)
findElementsByName in interface FindsByNamefindElementsByName in class org.openqa.selenium.remote.RemoteWebDriverpublic List<WebElement> findElementsByPartialLinkText(String text)
findElementsByPartialLinkText in interface FindsByLinkTextfindElementsByPartialLinkText in class org.openqa.selenium.remote.RemoteWebDriverpublic List<WebElement> findElementsByTagName(String tagName)
findElementsByTagName in interface FindsByTagNamefindElementsByTagName in class org.openqa.selenium.remote.RemoteWebDriverpublic List<WebElement> findElementsByXPath(String expr)
findElementsByXPath in interface FindsByXPathfindElementsByXPath in class org.openqa.selenium.remote.RemoteWebDriverpublic void get(String url)
WebDriver.Navigation.to(String).public Capabilities getCapabilities()
getCapabilities in interface HasCapabilitiesgetCapabilities in class org.openqa.selenium.remote.RemoteWebDriverpublic org.openqa.selenium.remote.CommandExecutor getCommandExecutor()
getCommandExecutor in class org.openqa.selenium.remote.RemoteWebDriverpublic String getCurrentUrl()
getCurrentUrl in interface WebDrivergetCurrentUrl in class org.openqa.selenium.remote.RemoteWebDriverpublic org.openqa.selenium.remote.ErrorHandler getErrorHandler()
getErrorHandler in class org.openqa.selenium.remote.RemoteWebDriverpublic org.openqa.selenium.remote.FileDetector getFileDetector()
getFileDetector in class org.openqa.selenium.remote.RemoteWebDriverpublic Keyboard getKeyboard()
getKeyboard in interface HasInputDevicesgetKeyboard in class org.openqa.selenium.remote.RemoteWebDriverpublic Mouse getMouse()
getMouse in interface HasInputDevicesgetMouse in class org.openqa.selenium.remote.RemoteWebDriverpublic String getPageSource()
getPageSource in interface WebDrivergetPageSource in class org.openqa.selenium.remote.RemoteWebDriverpublic <X> X getScreenshotAs(OutputType<X> outputType) throws WebDriverException
TakesScreenshotFor WebDriver extending TakesScreenshot, this makes a best effort depending on the browser to return the following in order of preference:
For WebElement extending TakesScreenshot, this makes a best effort depending on the browser to return the following in order of preference: - The entire content of the HTML element - The visisble portion of the HTML element
getScreenshotAs in interface TakesScreenshotgetScreenshotAs in class org.openqa.selenium.remote.RemoteWebDriverX - Return type for getScreenshotAs.outputType - target type, @see OutputTypeWebDriverException - on failure.public org.openqa.selenium.remote.SessionId getSessionId()
getSessionId in class org.openqa.selenium.remote.RemoteWebDriverpublic int getStatusCode()
public String getTitle()
public String getWindowHandle()
getWindowHandle in interface WebDrivergetWindowHandle in class org.openqa.selenium.remote.RemoteWebDriverpublic Set<String> getWindowHandles()
WebDriver.switchTo().WebDriver.Options.window()getWindowHandles in interface WebDrivergetWindowHandles in class org.openqa.selenium.remote.RemoteWebDriverpublic void init()
public static void initWorkThread()
public void kill()
public WebDriver.Options manage()
manage in interface WebDrivermanage in class org.openqa.selenium.remote.RemoteWebDriverWebDriver.Optionspublic File mediaDir()
public WebDriver.Navigation navigate()
navigate in interface WebDrivernavigate in class org.openqa.selenium.remote.RemoteWebDriverWebDriver.Navigation that allows the selection of what to
do nextpublic void pageWait()
The behavior of this wait algorithm can be configured by
Settings.Builder.ajaxWait(long) and
Settings.Builder.ajaxResourceTimeout(long).
public void quit()
public void reset()
public void reset(Capabilities capabilities)
Note: it's not possible to switch between headless and GUI mode. You must quit this browser and create a new instance.
capabilities - Capabilities to take effect, superseding the original onespublic void reset(Settings settings)
Note: it's not possible to switch between headless and GUI mode. You must quit this browser and create a new instance.
settings - New settings to take effect, superseding the original onespublic WebDriver.TargetLocator switchTo()
switchTo in interface WebDriverswitchTo in class org.openqa.selenium.remote.RemoteWebDriverWebDriver.TargetLocatorCopyright © 2014-2017 jBrowserDriver committers.
Project homepage: https://github.com/machinepublishers/jbrowserdriver