public class RemoteWebDriver extends java.lang.Object implements WebDriver, JavascriptExecutor, FindsById, FindsByClassName, FindsByLinkText, FindsByName, FindsByCssSelector, FindsByTagName, FindsByXPath, HasInputDevices, HasCapabilities, TakesScreenshot
Modifier and Type | Class and Description |
---|---|
protected class |
RemoteWebDriver.RemoteTargetLocator |
protected class |
RemoteWebDriver.RemoteWebDriverOptions |
static class |
RemoteWebDriver.When |
WebDriver.ImeHandler, WebDriver.Navigation, WebDriver.Options, WebDriver.TargetLocator, WebDriver.Timeouts, WebDriver.Window
Modifier | Constructor and Description |
---|---|
protected |
RemoteWebDriver() |
|
RemoteWebDriver(Capabilities desiredCapabilities) |
|
RemoteWebDriver(CommandExecutor executor,
Capabilities desiredCapabilities) |
|
RemoteWebDriver(CommandExecutor executor,
Capabilities desiredCapabilities,
Capabilities requiredCapabilities) |
|
RemoteWebDriver(java.net.URL remoteAddress,
Capabilities desiredCapabilities) |
|
RemoteWebDriver(java.net.URL remoteAddress,
Capabilities desiredCapabilities,
Capabilities requiredCapabilities) |
Modifier and Type | Method and Description |
---|---|
void |
close()
Close the current window, quitting the browser if it's the last window currently open.
|
protected Response |
execute(java.lang.String command) |
protected Response |
execute(java.lang.String driverCommand,
java.util.Map<java.lang.String,?> parameters) |
java.lang.Object |
executeAsyncScript(java.lang.String script,
java.lang.Object... args)
Execute an asynchronous piece of JavaScript in the context of the currently selected frame or
window.
|
java.lang.Object |
executeScript(java.lang.String script,
java.lang.Object... args)
Executes JavaScript in the context of the currently selected frame or window.
|
WebElement |
findElement(By by)
Find the first
WebElement using the given method. |
protected WebElement |
findElement(java.lang.String by,
java.lang.String using) |
WebElement |
findElementByClassName(java.lang.String using) |
WebElement |
findElementByCssSelector(java.lang.String using) |
WebElement |
findElementById(java.lang.String using) |
WebElement |
findElementByLinkText(java.lang.String using) |
WebElement |
findElementByName(java.lang.String using) |
WebElement |
findElementByPartialLinkText(java.lang.String using) |
WebElement |
findElementByTagName(java.lang.String using) |
WebElement |
findElementByXPath(java.lang.String using) |
java.util.List<WebElement> |
findElements(By by)
Find all elements within the current page using the given mechanism.
|
protected java.util.List<WebElement> |
findElements(java.lang.String by,
java.lang.String using) |
java.util.List<WebElement> |
findElementsByClassName(java.lang.String using) |
java.util.List<WebElement> |
findElementsByCssSelector(java.lang.String using) |
java.util.List<WebElement> |
findElementsById(java.lang.String using) |
java.util.List<WebElement> |
findElementsByLinkText(java.lang.String using) |
java.util.List<WebElement> |
findElementsByName(java.lang.String using) |
java.util.List<WebElement> |
findElementsByPartialLinkText(java.lang.String using) |
java.util.List<WebElement> |
findElementsByTagName(java.lang.String using) |
java.util.List<WebElement> |
findElementsByXPath(java.lang.String using) |
void |
get(java.lang.String url)
Load a new web page in the current browser window.
|
Capabilities |
getCapabilities() |
CommandExecutor |
getCommandExecutor() |
java.lang.String |
getCurrentUrl()
Get a string representing the current URL that the browser is looking at.
|
protected org.openqa.selenium.remote.internal.JsonToWebElementConverter |
getElementConverter() |
ErrorHandler |
getErrorHandler() |
protected ExecuteMethod |
getExecuteMethod() |
FileDetector |
getFileDetector() |
Keyboard |
getKeyboard() |
Mouse |
getMouse() |
java.lang.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.
|
SessionId |
getSessionId() |
java.lang.String |
getTitle()
The title of the current page.
|
java.lang.String |
getWindowHandle()
Return an opaque handle to this window that uniquely identifies it within this driver instance.
|
java.util.Set<java.lang.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() |
protected void |
log(SessionId sessionId,
java.lang.String commandName,
java.lang.Object toLog,
RemoteWebDriver.When when)
Override this to be notified at key points in the execution of a command.
|
WebDriver.Options |
manage()
Gets the Option interface
|
WebDriver.Navigation |
navigate()
An abstraction allowing the driver to access the browser's history and to navigate to a given
URL.
|
void |
quit()
Quits this driver, closing every associated window.
|
protected void |
setCommandExecutor(CommandExecutor executor) |
protected void |
setElementConverter(org.openqa.selenium.remote.internal.JsonToWebElementConverter converter) |
void |
setErrorHandler(ErrorHandler handler) |
void |
setFileDetector(FileDetector detector)
Set the file detector to be used when sending keyboard input.
|
protected void |
setFoundBy(SearchContext context,
WebElement element,
java.lang.String by,
java.lang.String using) |
void |
setLogLevel(java.util.logging.Level level)
Sets the RemoteWebDriver's client log level.
|
protected void |
setSessionId(java.lang.String opaqueKey) |
protected void |
startClient()
Method called before
starting a new session . |
protected void |
startSession(Capabilities desiredCapabilities) |
protected void |
startSession(Capabilities desiredCapabilities,
Capabilities requiredCapabilities) |
protected void |
stopClient()
Method called after executing a
quit() command. |
WebDriver.TargetLocator |
switchTo()
Send future commands to a different frame or window.
|
java.lang.String |
toString() |
protected RemoteWebDriver()
public RemoteWebDriver(CommandExecutor executor, Capabilities desiredCapabilities, Capabilities requiredCapabilities)
public RemoteWebDriver(CommandExecutor executor, Capabilities desiredCapabilities)
public RemoteWebDriver(Capabilities desiredCapabilities)
public RemoteWebDriver(java.net.URL remoteAddress, Capabilities desiredCapabilities, Capabilities requiredCapabilities)
public RemoteWebDriver(java.net.URL remoteAddress, Capabilities desiredCapabilities)
public void setFileDetector(FileDetector detector)
detector
- The detector to use. Must not be null.FileDetector
,
LocalFileDetector
,
UselessFileDetector
public SessionId getSessionId()
protected void setSessionId(java.lang.String opaqueKey)
protected void startSession(Capabilities desiredCapabilities)
protected void startSession(Capabilities desiredCapabilities, Capabilities requiredCapabilities)
protected void startClient()
starting a new session
. The default
implementation is a no-op, but subtypes should override this method to define custom behavior.protected void stopClient()
quit()
command. Subtypespublic ErrorHandler getErrorHandler()
public void setErrorHandler(ErrorHandler handler)
public CommandExecutor getCommandExecutor()
protected void setCommandExecutor(CommandExecutor executor)
public Capabilities getCapabilities()
getCapabilities
in interface HasCapabilities
public void get(java.lang.String url)
WebDriver
WebDriver.Navigation.to(String)
.public java.lang.String getTitle()
WebDriver
public java.lang.String getCurrentUrl()
WebDriver
getCurrentUrl
in interface WebDriver
public <X> X getScreenshotAs(OutputType<X> outputType) throws WebDriverException
TakesScreenshot
For 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 TakesScreenshot
X
- Return type for getScreenshotAs.outputType
- target type, @see OutputTypeWebDriverException
- on failure.public java.util.List<WebElement> findElements(By by)
WebDriver
findElements
in interface SearchContext
findElements
in interface WebDriver
by
- The locating mechanism to useWebElement
s, or an empty list if nothing matchesBy
,
WebDriver.Timeouts
public WebElement findElement(By by)
WebDriver
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 SearchContext
findElement
in interface WebDriver
by
- The locating mechanismBy
,
WebDriver.Timeouts
protected WebElement findElement(java.lang.String by, java.lang.String using)
protected void setFoundBy(SearchContext context, WebElement element, java.lang.String by, java.lang.String using)
protected java.util.List<WebElement> findElements(java.lang.String by, java.lang.String using)
public WebElement findElementById(java.lang.String using)
findElementById
in interface FindsById
public java.util.List<WebElement> findElementsById(java.lang.String using)
findElementsById
in interface FindsById
public WebElement findElementByLinkText(java.lang.String using)
findElementByLinkText
in interface FindsByLinkText
public java.util.List<WebElement> findElementsByLinkText(java.lang.String using)
findElementsByLinkText
in interface FindsByLinkText
public WebElement findElementByPartialLinkText(java.lang.String using)
findElementByPartialLinkText
in interface FindsByLinkText
public java.util.List<WebElement> findElementsByPartialLinkText(java.lang.String using)
findElementsByPartialLinkText
in interface FindsByLinkText
public WebElement findElementByTagName(java.lang.String using)
findElementByTagName
in interface FindsByTagName
public java.util.List<WebElement> findElementsByTagName(java.lang.String using)
findElementsByTagName
in interface FindsByTagName
public WebElement findElementByName(java.lang.String using)
findElementByName
in interface FindsByName
public java.util.List<WebElement> findElementsByName(java.lang.String using)
findElementsByName
in interface FindsByName
public WebElement findElementByClassName(java.lang.String using)
findElementByClassName
in interface FindsByClassName
public java.util.List<WebElement> findElementsByClassName(java.lang.String using)
findElementsByClassName
in interface FindsByClassName
public WebElement findElementByCssSelector(java.lang.String using)
findElementByCssSelector
in interface FindsByCssSelector
public java.util.List<WebElement> findElementsByCssSelector(java.lang.String using)
findElementsByCssSelector
in interface FindsByCssSelector
public WebElement findElementByXPath(java.lang.String using)
findElementByXPath
in interface FindsByXPath
public java.util.List<WebElement> findElementsByXPath(java.lang.String using)
findElementsByXPath
in interface FindsByXPath
public java.lang.String getPageSource()
WebDriver
getPageSource
in interface WebDriver
public void close()
WebDriver
public void quit()
WebDriver
public java.util.Set<java.lang.String> getWindowHandles()
WebDriver
WebDriver.switchTo()
.WebDriver.Options.window()
getWindowHandles
in interface WebDriver
public java.lang.String getWindowHandle()
WebDriver
getWindowHandle
in interface WebDriver
public java.lang.Object executeScript(java.lang.String script, java.lang.Object... args)
JavascriptExecutor
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 JavascriptExecutor
script
- The JavaScript to executeargs
- The arguments to the script. May be emptypublic java.lang.Object executeAsyncScript(java.lang.String script, java.lang.Object... args)
JavascriptExecutor
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("[email protected]");
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 JavascriptExecutor
script
- The JavaScript to execute.args
- The arguments to the script. May be empty.WebDriver.Timeouts.setScriptTimeout(long, java.util.concurrent.TimeUnit)
public WebDriver.TargetLocator switchTo()
WebDriver
switchTo
in interface WebDriver
WebDriver.TargetLocator
public WebDriver.Navigation navigate()
WebDriver
navigate
in interface WebDriver
WebDriver.Navigation
that allows the selection of what to
do nextpublic WebDriver.Options manage()
WebDriver
manage
in interface WebDriver
WebDriver.Options
protected void setElementConverter(org.openqa.selenium.remote.internal.JsonToWebElementConverter converter)
protected org.openqa.selenium.remote.internal.JsonToWebElementConverter getElementConverter()
public void setLogLevel(java.util.logging.Level level)
level
- The log level to use.protected Response execute(java.lang.String driverCommand, java.util.Map<java.lang.String,?> parameters)
protected Response execute(java.lang.String command)
protected ExecuteMethod getExecuteMethod()
public Keyboard getKeyboard()
getKeyboard
in interface HasInputDevices
public Mouse getMouse()
getMouse
in interface HasInputDevices
protected void log(SessionId sessionId, java.lang.String commandName, java.lang.Object toLog, RemoteWebDriver.When when)
sessionId
- the session id.commandName
- the command that is being executed.toLog
- any data that might be interesting.public FileDetector getFileDetector()
public java.lang.String toString()
toString
in class java.lang.Object