public interface WebDriver extends SearchContext
WebElement
s
Key methods are get(String)
, which is used to load a new web page, and the
various methods similar to findElement(By)
, which is used to find
WebElement
s.
Currently, you will need to instantiate implementations of this interface directly. It is hoped that you write your tests against this interface so that you may "swap in" a more fully featured browser when there is a requirement for one.
Note that all methods that use XPath to locate elements will throw a RuntimeException
should there be an error thrown by the underlying XPath engine.
Modifier and Type | Interface and Description |
---|---|
static interface |
WebDriver.ImeHandler
An interface for managing input methods.
|
static interface |
WebDriver.Navigation |
static interface |
WebDriver.Options
An interface for managing stuff you would do in a browser menu
|
static interface |
WebDriver.TargetLocator
Used to locate a given frame or window.
|
static interface |
WebDriver.Timeouts
An interface for managing timeout behavior for WebDriver instances.
|
static interface |
WebDriver.Window |
Modifier and Type | Method and Description |
---|---|
void |
close()
Close the current window, quitting the browser if it's the last window currently open.
|
WebElement |
findElement(By by)
Find the first
WebElement using the given method. |
java.util.List<WebElement> |
findElements(By by)
Find all elements within the current page using the given mechanism.
|
void |
get(java.lang.String url)
Load a new web page in the current browser window.
|
java.lang.String |
getCurrentUrl()
Get a string representing the current URL that the browser is looking at.
|
java.lang.String |
getPageSource()
Get the source of the last loaded page.
|
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() .WebDriver.Options.window() |
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.
|
WebDriver.TargetLocator |
switchTo()
Send future commands to a different frame or window.
|
void get(java.lang.String url)
WebDriver.Navigation.to(String)
.url
- The URL to load. It is best to use a fully qualified URLjava.lang.String getCurrentUrl()
java.lang.String getTitle()
java.util.List<WebElement> findElements(By by)
findElements
in interface SearchContext
by
- The locating mechanism to useWebElement
s, or an empty list if nothing matchesBy
,
WebDriver.Timeouts
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 findElements(By)
and assert zero length response instead.findElement
in interface SearchContext
by
- The locating mechanismNoSuchElementException
- If no matching elements are foundBy
,
WebDriver.Timeouts
java.lang.String getPageSource()
void close()
void quit()
java.util.Set<java.lang.String> getWindowHandles()
switchTo()
.WebDriver.Options.window()
java.lang.String getWindowHandle()
WebDriver.TargetLocator switchTo()
WebDriver.TargetLocator
WebDriver.Navigation navigate()
WebDriver.Navigation
that allows the selection of what to
do nextWebDriver.Options manage()
WebDriver.Options