public class RemoteWebDriver extends Object implements WebDriver, JavascriptExecutor, FindsById, FindsByClassName, FindsByLinkText, FindsByName, FindsByCssSelector, FindsByTagName, FindsByXPath, HasInputDevices, HasCapabilities, TakesScreenshot
| 限定符和类型 | 类和说明 |
|---|---|
static class |
RemoteWebDriver.When |
WebDriver.ImeHandler, WebDriver.Navigation, WebDriver.Options, WebDriver.TargetLocator, WebDriver.Timeouts, WebDriver.Window| 构造器和说明 |
|---|
RemoteWebDriver(Capabilities desiredCapabilities) |
RemoteWebDriver(CommandExecutor executor,
Capabilities desiredCapabilities) |
RemoteWebDriver(CommandExecutor executor,
Capabilities desiredCapabilities,
Capabilities requiredCapabilities) |
RemoteWebDriver(URL remoteAddress,
Capabilities desiredCapabilities) |
RemoteWebDriver(URL remoteAddress,
Capabilities desiredCapabilities,
Capabilities requiredCapabilities) |
| 限定符和类型 | 方法和说明 |
|---|---|
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.
|
WebElement |
findElement(By by)
Find the first
WebElement using the given method. |
WebElement |
findElementByClassName(String using) |
WebElement |
findElementByCssSelector(String using) |
WebElement |
findElementById(String using) |
WebElement |
findElementByLinkText(String using) |
WebElement |
findElementByName(String using) |
WebElement |
findElementByPartialLinkText(String using) |
WebElement |
findElementByTagName(String using) |
WebElement |
findElementByXPath(String using) |
List<WebElement> |
findElements(By by)
Find all elements within the current page using the given mechanism.
|
List<WebElement> |
findElementsByClassName(String using) |
List<WebElement> |
findElementsByCssSelector(String using) |
List<WebElement> |
findElementsById(String using) |
List<WebElement> |
findElementsByLinkText(String using) |
List<WebElement> |
findElementsByName(String using) |
List<WebElement> |
findElementsByPartialLinkText(String using) |
List<WebElement> |
findElementsByTagName(String using) |
List<WebElement> |
findElementsByXPath(String using) |
void |
get(String url)
Load a new web page in the current browser window.
|
Capabilities |
getCapabilities() |
CommandExecutor |
getCommandExecutor() |
String |
getCurrentUrl()
Get a string representing the current URL that the browser is looking at.
|
ErrorHandler |
getErrorHandler() |
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.
|
SessionId |
getSessionId() |
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 |
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.
|
void |
setErrorHandler(ErrorHandler handler) |
void |
setFileDetector(FileDetector detector)
Set the file detector to be used when sending keyboard input.
|
void |
setLogLevel(Level level)
Sets the RemoteWebDriver's client log level.
|
WebDriver.TargetLocator |
switchTo()
Send future commands to a different frame or window.
|
String |
toString() |
public RemoteWebDriver(CommandExecutor executor, Capabilities desiredCapabilities, Capabilities requiredCapabilities)
public RemoteWebDriver(CommandExecutor executor, Capabilities desiredCapabilities)
public RemoteWebDriver(Capabilities desiredCapabilities)
public RemoteWebDriver(URL remoteAddress, Capabilities desiredCapabilities, Capabilities requiredCapabilities)
public RemoteWebDriver(URL remoteAddress, Capabilities desiredCapabilities)
public void setFileDetector(FileDetector detector)
detector - The detector to use. Must not be null.FileDetector,
LocalFileDetector,
UselessFileDetectorpublic SessionId getSessionId()
public ErrorHandler getErrorHandler()
public void setErrorHandler(ErrorHandler handler)
public CommandExecutor getCommandExecutor()
public Capabilities getCapabilities()
getCapabilities 在接口中 HasCapabilitiespublic void get(String url)
WebDriverWebDriver.Navigation.to(String).public String getCurrentUrl()
WebDrivergetCurrentUrl 在接口中 WebDriverpublic <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 visible portion of the HTML element
getScreenshotAs 在接口中 TakesScreenshotX - Return type for getScreenshotAs.outputType - target type, @see OutputTypeWebDriverException - on failure.public List<WebElement> findElements(By by)
WebDriverfindElements 在接口中 SearchContextfindElements 在接口中 WebDriverby - The locating mechanism to useWebElements, or an empty list if nothing matchesBy,
WebDriver.Timeoutspublic WebElement findElement(By by)
WebDriverWebElement 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 在接口中 SearchContextfindElement 在接口中 WebDriverby - The locating mechanismBy,
WebDriver.Timeoutspublic WebElement findElementById(String using)
findElementById 在接口中 FindsByIdpublic List<WebElement> findElementsById(String using)
findElementsById 在接口中 FindsByIdpublic WebElement findElementByLinkText(String using)
findElementByLinkText 在接口中 FindsByLinkTextpublic List<WebElement> findElementsByLinkText(String using)
findElementsByLinkText 在接口中 FindsByLinkTextpublic WebElement findElementByPartialLinkText(String using)
findElementByPartialLinkText 在接口中 FindsByLinkTextpublic List<WebElement> findElementsByPartialLinkText(String using)
findElementsByPartialLinkText 在接口中 FindsByLinkTextpublic WebElement findElementByTagName(String using)
findElementByTagName 在接口中 FindsByTagNamepublic List<WebElement> findElementsByTagName(String using)
findElementsByTagName 在接口中 FindsByTagNamepublic WebElement findElementByName(String using)
findElementByName 在接口中 FindsByNamepublic List<WebElement> findElementsByName(String using)
findElementsByName 在接口中 FindsByNamepublic WebElement findElementByClassName(String using)
findElementByClassName 在接口中 FindsByClassNamepublic List<WebElement> findElementsByClassName(String using)
findElementsByClassName 在接口中 FindsByClassNamepublic WebElement findElementByCssSelector(String using)
findElementByCssSelector 在接口中 FindsByCssSelectorpublic List<WebElement> findElementsByCssSelector(String using)
findElementsByCssSelector 在接口中 FindsByCssSelectorpublic WebElement findElementByXPath(String using)
findElementByXPath 在接口中 FindsByXPathpublic List<WebElement> findElementsByXPath(String using)
findElementsByXPath 在接口中 FindsByXPathpublic String getPageSource()
WebDrivergetPageSource 在接口中 WebDriverpublic void close()
WebDriverpublic void quit()
WebDriverpublic Set<String> getWindowHandles()
WebDriverWebDriver.switchTo().WebDriver.Options.window()getWindowHandles 在接口中 WebDriverpublic String getWindowHandle()
WebDrivergetWindowHandle 在接口中 WebDriverpublic Object executeScript(String script, 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 在接口中 JavascriptExecutorscript - The JavaScript to executeargs - The arguments to the script. May be emptypublic Object executeAsyncScript(String script, Object... args)
JavascriptExecutorsynchronous 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 在接口中 JavascriptExecutorscript - 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()
WebDriverswitchTo 在接口中 WebDriverWebDriver.TargetLocatorpublic WebDriver.Navigation navigate()
WebDrivernavigate 在接口中 WebDriverWebDriver.Navigation that allows the selection of what to
do nextpublic WebDriver.Options manage()
WebDrivermanage 在接口中 WebDriverWebDriver.Optionspublic void setLogLevel(Level level)
level - The log level to use.public Keyboard getKeyboard()
getKeyboard 在接口中 HasInputDevicespublic Mouse getMouse()
getMouse 在接口中 HasInputDevicespublic FileDetector getFileDetector()