|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.openqa.selenium.htmlunit.HtmlUnitDriver
public class HtmlUnitDriver
| Nested Class Summary | |
|---|---|
protected static interface |
HtmlUnitDriver.JavaScriptResultsCollection
|
| Nested classes/interfaces inherited from interface org.openqa.selenium.WebDriver |
|---|
WebDriver.ImeHandler, WebDriver.Navigation, WebDriver.Options, WebDriver.TargetLocator, WebDriver.Timeouts, WebDriver.Window |
| Field Summary | |
|---|---|
static java.lang.String |
INVALIDSELECTIONERROR
|
static java.lang.String |
INVALIDXPATHERROR
|
| Constructor Summary | |
|---|---|
HtmlUnitDriver()
|
|
HtmlUnitDriver(boolean enableJavascript)
|
|
HtmlUnitDriver(com.gargoylesoftware.htmlunit.BrowserVersion version)
|
|
HtmlUnitDriver(Capabilities capabilities)
Note: There are two configuration modes for the HtmlUnitDriver using this constructor. |
|
| Method Summary | ||
|---|---|---|
void |
close()
Close the current window, quitting the browser if it's the last window currently open. |
|
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. |
|
WebElement |
findElementByCssSelector(java.lang.String using)
|
|
WebElement |
findElementById(java.lang.String id)
|
|
WebElement |
findElementByLinkText(java.lang.String selector)
|
|
WebElement |
findElementByName(java.lang.String name)
|
|
WebElement |
findElementByPartialLinkText(java.lang.String using)
|
|
WebElement |
findElementByTagName(java.lang.String name)
|
|
WebElement |
findElementByXPath(java.lang.String selector)
|
|
java.util.List<WebElement> |
findElements(By by)
Find all elements within the current page using the given mechanism. |
|
java.util.List<WebElement> |
findElementsByCssSelector(java.lang.String using)
|
|
java.util.List<WebElement> |
findElementsById(java.lang.String id)
|
|
java.util.List<WebElement> |
findElementsByLinkText(java.lang.String selector)
|
|
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 selector)
|
|
void |
get(java.lang.String url)
Load a new web page in the current browser window. |
|
protected void |
get(java.net.URL fullUrl)
Allows HtmlUnit's about:blank to be loaded in the constructor, and may be useful for other tests? |
|
Capabilities |
getCapabilities()
|
|
java.lang.String |
getCurrentUrl()
Get a string representing the current URL that the browser is looking at. |
|
protected com.gargoylesoftware.htmlunit.WebWindow |
getCurrentWindow()
|
|
Keyboard |
getKeyboard()
|
|
Mouse |
getMouse()
|
|
java.lang.String |
getPageSource()
Get the source of the last loaded page. |
|
java.lang.String |
getTitle()
The title of the current page. |
|
protected com.gargoylesoftware.htmlunit.WebClient |
getWebClient()
|
|
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
|
implicitlyWaitFor(java.util.concurrent.Callable<X> condition)
|
|
boolean |
isJavascriptEnabled()
|
|
protected com.gargoylesoftware.htmlunit.Page |
lastPage()
|
|
WebDriver.Options |
manage()
Gets the Option interface |
|
protected com.gargoylesoftware.htmlunit.WebClient |
modifyWebClient(com.gargoylesoftware.htmlunit.WebClient client)
Child classes can override this method to customise the webclient that the HtmlUnit driver uses. |
|
WebDriver.Navigation |
navigate()
An abstraction allowing the driver to access the browser's history and to navigate to a given URL. |
|
protected WebElement |
newHtmlUnitWebElement(com.gargoylesoftware.htmlunit.html.HtmlElement element)
|
|
protected com.gargoylesoftware.htmlunit.WebClient |
newWebClient(com.gargoylesoftware.htmlunit.BrowserVersion version)
Create the underlying webclient, but don't set any fields on it. |
|
protected void |
pickWindow()
|
|
void |
quit()
Quits this driver, closing every associated window. |
|
void |
setAutoProxy(java.lang.String autoProxyUrl)
|
|
void |
setJavascriptEnabled(boolean enableJavascript)
|
|
void |
setProxy(java.lang.String host,
int port)
|
|
WebDriver.TargetLocator |
switchTo()
Send future commands to a different frame or window. |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final java.lang.String INVALIDXPATHERROR
public static final java.lang.String INVALIDSELECTIONERROR
| Constructor Detail |
|---|
public HtmlUnitDriver(com.gargoylesoftware.htmlunit.BrowserVersion version)
public HtmlUnitDriver()
public HtmlUnitDriver(boolean enableJavascript)
public HtmlUnitDriver(Capabilities capabilities)
| Method Detail |
|---|
protected com.gargoylesoftware.htmlunit.WebClient newWebClient(com.gargoylesoftware.htmlunit.BrowserVersion version)
version - Which browser to emulate
protected com.gargoylesoftware.htmlunit.WebClient modifyWebClient(com.gargoylesoftware.htmlunit.WebClient client)
client - The client to modify
public void setProxy(java.lang.String host,
int port)
public void setAutoProxy(java.lang.String autoProxyUrl)
public Capabilities getCapabilities()
getCapabilities in interface HasCapabilitiespublic void get(java.lang.String url)
WebDriverWebDriver.Navigation.to(String).
get in interface WebDriverurl - The URL to load. It is best to use a fully qualified URLprotected void get(java.net.URL fullUrl)
fullUrl - The URL to visitprotected void pickWindow()
public java.lang.String getCurrentUrl()
WebDriver
getCurrentUrl in interface WebDriverpublic java.lang.String getTitle()
WebDriver
getTitle in interface WebDriverpublic 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 in interface SearchContextfindElement in interface WebDriverby - The locating mechanism
By,
WebDriver.Timeoutspublic java.util.List<WebElement> findElements(By by)
WebDriver
findElements in interface SearchContextfindElements in interface WebDriverby - The locating mechanism to use
WebElements, or an empty list if nothing matchesBy,
WebDriver.Timeoutspublic java.lang.String getPageSource()
WebDriver
getPageSource in interface WebDriverpublic void close()
WebDriver
close in interface WebDriverpublic void quit()
WebDriver
quit in interface WebDriverpublic java.util.Set<java.lang.String> getWindowHandles()
WebDriver#switchTo().window(String)
getWindowHandles in interface WebDriverpublic 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 JavascriptExecutorscript - The JavaScript to executeargs - The arguments to the script. May be empty
public java.lang.Object executeAsyncScript(java.lang.String script,
java.lang.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:
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"));
executeAsyncScript in interface JavascriptExecutorscript - The JavaScript to execute.args - The arguments to the script. May be empty.
public Keyboard getKeyboard()
getKeyboard in interface HasInputDevicespublic Mouse getMouse()
getMouse in interface HasInputDevicespublic WebDriver.TargetLocator switchTo()
WebDriver
switchTo in interface WebDriverWebDriver.TargetLocatorpublic WebDriver.Navigation navigate()
WebDriver
navigate in interface WebDriverWebDriver.Navigation that allows the selection of what to
do nextprotected com.gargoylesoftware.htmlunit.Page lastPage()
public WebElement findElementByLinkText(java.lang.String selector)
findElementByLinkText in interface FindsByLinkTextprotected WebElement newHtmlUnitWebElement(com.gargoylesoftware.htmlunit.html.HtmlElement element)
public java.util.List<WebElement> findElementsByLinkText(java.lang.String selector)
findElementsByLinkText in interface FindsByLinkTextpublic WebElement findElementById(java.lang.String id)
findElementById in interface FindsByIdpublic java.util.List<WebElement> findElementsById(java.lang.String id)
findElementsById in interface FindsByIdpublic WebElement findElementByCssSelector(java.lang.String using)
findElementByCssSelector in interface FindsByCssSelectorpublic java.util.List<WebElement> findElementsByCssSelector(java.lang.String using)
findElementsByCssSelector in interface FindsByCssSelectorpublic WebElement findElementByName(java.lang.String name)
findElementByName in interface FindsByNamepublic java.util.List<WebElement> findElementsByName(java.lang.String using)
findElementsByName in interface FindsByNamepublic WebElement findElementByTagName(java.lang.String name)
findElementByTagName in interface FindsByTagNamepublic java.util.List<WebElement> findElementsByTagName(java.lang.String using)
findElementsByTagName in interface FindsByTagNamepublic WebElement findElementByXPath(java.lang.String selector)
findElementByXPath in interface FindsByXPathpublic java.util.List<WebElement> findElementsByXPath(java.lang.String selector)
findElementsByXPath in interface FindsByXPathpublic boolean isJavascriptEnabled()
public void setJavascriptEnabled(boolean enableJavascript)
protected <X> X implicitlyWaitFor(java.util.concurrent.Callable<X> condition)
protected com.gargoylesoftware.htmlunit.WebClient getWebClient()
protected com.gargoylesoftware.htmlunit.WebWindow getCurrentWindow()
public WebDriver.Options manage()
WebDriver
manage in interface WebDriverWebDriver.Optionspublic WebElement findElementByPartialLinkText(java.lang.String using)
findElementByPartialLinkText in interface FindsByLinkTextpublic java.util.List<WebElement> findElementsByPartialLinkText(java.lang.String using)
findElementsByPartialLinkText in interface FindsByLinkText
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||