org.openqa.selenium.remote
Class RemoteWebDriver

java.lang.Object
  extended by org.openqa.selenium.remote.RemoteWebDriver
All Implemented Interfaces:
HasCapabilities, HasInputDevices, FindsByClassName, FindsByCssSelector, FindsById, FindsByLinkText, FindsByName, FindsByTagName, FindsByXPath, JavascriptExecutor, SearchContext, WebDriver
Direct Known Subclasses:
AndroidDriver, ChromeDriver, FirefoxDriver, InternetExplorerDriver, IPhoneDriver, SafariDriver

public class RemoteWebDriver
extends java.lang.Object
implements WebDriver, JavascriptExecutor, FindsById, FindsByClassName, FindsByLinkText, FindsByName, FindsByCssSelector, FindsByTagName, FindsByXPath, HasInputDevices, HasCapabilities


Nested Class Summary
protected  class RemoteWebDriver.RemoteTargetLocator
           
protected  class RemoteWebDriver.RemoteWebDriverOptions
           
static class RemoteWebDriver.When
           
 
Nested classes/interfaces inherited from interface org.openqa.selenium.WebDriver
WebDriver.ImeHandler, WebDriver.Navigation, WebDriver.Options, WebDriver.TargetLocator, WebDriver.Timeouts, WebDriver.Window
 
Constructor Summary
protected RemoteWebDriver()
           
  RemoteWebDriver(Capabilities desiredCapabilities)
           
  RemoteWebDriver(CommandExecutor executor, Capabilities desiredCapabilities)
           
  RemoteWebDriver(java.net.URL remoteAddress, Capabilities desiredCapabilities)
           
 
Method Summary
 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.
 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 #switchTo().window(String)
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 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 stopClient()
          Method called after executing a quit() command.
 WebDriver.TargetLocator switchTo()
          Send future commands to a different frame or window.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

RemoteWebDriver

protected RemoteWebDriver()

RemoteWebDriver

public RemoteWebDriver(CommandExecutor executor,
                       Capabilities desiredCapabilities)

RemoteWebDriver

public RemoteWebDriver(Capabilities desiredCapabilities)

RemoteWebDriver

public RemoteWebDriver(java.net.URL remoteAddress,
                       Capabilities desiredCapabilities)
Method Detail

setFileDetector

public void setFileDetector(FileDetector detector)
Set the file detector to be used when sending keyboard input. By default, this is set to a file detector that does nothing.

Parameters:
detector - The detector to use. Must not be null.
See Also:
FileDetector, LocalFileDetector, UselessFileDetector

getSessionId

public SessionId getSessionId()

setSessionId

protected void setSessionId(java.lang.String opaqueKey)

startSession

protected void startSession(Capabilities desiredCapabilities)

startClient

protected void startClient()
Method called before starting a new session. The default implementation is a no-op, but subtypes should override this method to define custom behavior.


stopClient

protected void stopClient()
Method called after executing a quit() command. Subtypes


getErrorHandler

public ErrorHandler getErrorHandler()

getCommandExecutor

public CommandExecutor getCommandExecutor()

setCommandExecutor

protected void setCommandExecutor(CommandExecutor executor)

getCapabilities

public Capabilities getCapabilities()
Specified by:
getCapabilities in interface HasCapabilities
Returns:
The capabilities of the current driver.

get

public void get(java.lang.String url)
Description copied from interface: WebDriver
Load a new web page in the current browser window. This is done using an HTTP GET operation, and the method will block until the load is complete. This will follow redirects issued either by the server or as a meta-redirect from within the returned HTML. Should a meta-redirect "rest" for any duration of time, it is best to wait until this timeout is over, since should the underlying page change whilst your test is executing the results of future calls against this interface will be against the freshly loaded page. Synonym for WebDriver.Navigation.to(String).

Specified by:
get in interface WebDriver
Parameters:
url - The URL to load. It is best to use a fully qualified URL

getTitle

public java.lang.String getTitle()
Description copied from interface: WebDriver
The title of the current page.

Specified by:
getTitle in interface WebDriver
Returns:
The title of the current page, with leading and trailing whitespace stripped, or null if one is not already set

getCurrentUrl

public java.lang.String getCurrentUrl()
Description copied from interface: WebDriver
Get a string representing the current URL that the browser is looking at.

Specified by:
getCurrentUrl in interface WebDriver
Returns:
The URL of the page currently loaded in the browser

findElements

public java.util.List<WebElement> findElements(By by)
Description copied from interface: WebDriver
Find all elements within the current page using the given mechanism. This method is affected by the 'implicit wait' times in force at the time of execution. When implicitly waiting, this method will return as soon as there are more than 0 items in the found collection, or will return an empty list if the timeout is reached.

Specified by:
findElements in interface SearchContext
Specified by:
findElements in interface WebDriver
Parameters:
by - The locating mechanism to use
Returns:
A list of all WebElements, or an empty list if nothing matches
See Also:
By, WebDriver.Timeouts

findElement

public WebElement findElement(By by)
Description copied from interface: WebDriver
Find the first 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.

Specified by:
findElement in interface SearchContext
Specified by:
findElement in interface WebDriver
Parameters:
by - The locating mechanism
Returns:
The first matching element on the current page
See Also:
By, WebDriver.Timeouts

findElement

protected WebElement findElement(java.lang.String by,
                                 java.lang.String using)

setFoundBy

protected void setFoundBy(SearchContext context,
                          WebElement element,
                          java.lang.String by,
                          java.lang.String using)

findElements

protected java.util.List<WebElement> findElements(java.lang.String by,
                                                  java.lang.String using)

findElementById

public WebElement findElementById(java.lang.String using)
Specified by:
findElementById in interface FindsById

findElementsById

public java.util.List<WebElement> findElementsById(java.lang.String using)
Specified by:
findElementsById in interface FindsById

findElementByLinkText

public WebElement findElementByLinkText(java.lang.String using)
Specified by:
findElementByLinkText in interface FindsByLinkText

findElementsByLinkText

public java.util.List<WebElement> findElementsByLinkText(java.lang.String using)
Specified by:
findElementsByLinkText in interface FindsByLinkText

findElementByPartialLinkText

public WebElement findElementByPartialLinkText(java.lang.String using)
Specified by:
findElementByPartialLinkText in interface FindsByLinkText

findElementsByPartialLinkText

public java.util.List<WebElement> findElementsByPartialLinkText(java.lang.String using)
Specified by:
findElementsByPartialLinkText in interface FindsByLinkText

findElementByTagName

public WebElement findElementByTagName(java.lang.String using)
Specified by:
findElementByTagName in interface FindsByTagName

findElementsByTagName

public java.util.List<WebElement> findElementsByTagName(java.lang.String using)
Specified by:
findElementsByTagName in interface FindsByTagName

findElementByName

public WebElement findElementByName(java.lang.String using)
Specified by:
findElementByName in interface FindsByName

findElementsByName

public java.util.List<WebElement> findElementsByName(java.lang.String using)
Specified by:
findElementsByName in interface FindsByName

findElementByClassName

public WebElement findElementByClassName(java.lang.String using)
Specified by:
findElementByClassName in interface FindsByClassName

findElementsByClassName

public java.util.List<WebElement> findElementsByClassName(java.lang.String using)
Specified by:
findElementsByClassName in interface FindsByClassName

findElementByCssSelector

public WebElement findElementByCssSelector(java.lang.String using)
Specified by:
findElementByCssSelector in interface FindsByCssSelector

findElementsByCssSelector

public java.util.List<WebElement> findElementsByCssSelector(java.lang.String using)
Specified by:
findElementsByCssSelector in interface FindsByCssSelector

findElementByXPath

public WebElement findElementByXPath(java.lang.String using)
Specified by:
findElementByXPath in interface FindsByXPath

findElementsByXPath

public java.util.List<WebElement> findElementsByXPath(java.lang.String using)
Specified by:
findElementsByXPath in interface FindsByXPath

getPageSource

public java.lang.String getPageSource()
Description copied from interface: WebDriver
Get the source of the last loaded page. If the page has been modified after loading (for example, by Javascript) there is no guarantee that the returned text is that of the modified page. Please consult the documentation of the particular driver being used to determine whether the returned text reflects the current state of the page or the text last sent by the web server. The page source returned is a representation of the underlying DOM: do not expect it to be formatted or escaped in the same way as the response sent from the web server. Think of it as an artist's impression.

Specified by:
getPageSource in interface WebDriver
Returns:
The source of the current page

close

public void close()
Description copied from interface: WebDriver
Close the current window, quitting the browser if it's the last window currently open.

Specified by:
close in interface WebDriver

quit

public void quit()
Description copied from interface: WebDriver
Quits this driver, closing every associated window.

Specified by:
quit in interface WebDriver

getWindowHandles

public java.util.Set<java.lang.String> getWindowHandles()
Description copied from interface: WebDriver
Return a set of window handles which can be used to iterate over all open windows of this webdriver instance by passing them to #switchTo().window(String)

Specified by:
getWindowHandles in interface WebDriver
Returns:
A set of window handles which can be used to iterate over all open windows.

getWindowHandle

public java.lang.String getWindowHandle()
Description copied from interface: WebDriver
Return an opaque handle to this window that uniquely identifies it within this driver instance. This can be used to switch to this window at a later date

Specified by:
getWindowHandle in interface WebDriver

executeScript

public java.lang.Object executeScript(java.lang.String script,
                                      java.lang.Object... args)
Description copied from interface: JavascriptExecutor
Executes JavaScript in the context of the currently selected frame or window. The script fragment provided will be executed as the body of an anonymous function.

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"

Specified by:
executeScript in interface JavascriptExecutor
Parameters:
script - The JavaScript to execute
args - The arguments to the script. May be empty
Returns:
One of Boolean, Long, String, List or WebElement. Or null.

executeAsyncScript

public java.lang.Object executeAsyncScript(java.lang.String script,
                                           java.lang.Object... args)
Description copied from interface: JavascriptExecutor
Execute an asynchronous piece of JavaScript in the context of the currently selected frame or window. Unlike executing 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:

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 JSONObject((String) response);
   assertEquals("cheese", json.getString("food"));
 

Specified by:
executeAsyncScript in interface JavascriptExecutor
Parameters:
script - The JavaScript to execute.
args - The arguments to the script. May be empty.
Returns:
One of Boolean, Long, String, List, WebElement, or null.

switchTo

public WebDriver.TargetLocator switchTo()
Description copied from interface: WebDriver
Send future commands to a different frame or window.

Specified by:
switchTo in interface WebDriver
Returns:
A TargetLocator which can be used to select a frame or window
See Also:
WebDriver.TargetLocator

navigate

public WebDriver.Navigation navigate()
Description copied from interface: WebDriver
An abstraction allowing the driver to access the browser's history and to navigate to a given URL.

Specified by:
navigate in interface WebDriver
Returns:
A WebDriver.Navigation that allows the selection of what to do next

manage

public WebDriver.Options manage()
Description copied from interface: WebDriver
Gets the Option interface

Specified by:
manage in interface WebDriver
Returns:
An option interface
See Also:
WebDriver.Options

setElementConverter

protected void setElementConverter(org.openqa.selenium.remote.internal.JsonToWebElementConverter converter)

getElementConverter

protected org.openqa.selenium.remote.internal.JsonToWebElementConverter getElementConverter()

setLogLevel

public void setLogLevel(java.util.logging.Level level)
Sets the RemoteWebDriver's client log level.

Parameters:
level - The log level to use.

execute

protected Response execute(java.lang.String driverCommand,
                           java.util.Map<java.lang.String,?> parameters)

execute

protected Response execute(java.lang.String command)

getExecuteMethod

protected ExecuteMethod getExecuteMethod()

getKeyboard

public Keyboard getKeyboard()
Specified by:
getKeyboard in interface HasInputDevices

getMouse

public Mouse getMouse()
Specified by:
getMouse in interface HasInputDevices

log

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.

Parameters:
sessionId - the session id.
commandName - the command that is being executed.
toLog - any data that might be interesting.

getFileDetector

public FileDetector getFileDetector()

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object