Class webdriver.WebElement
Extends
.
Defined in: webdriver.js.
Constructor Attributes | Constructor Name and Description |
---|---|
webdriver.WebElement(driver, id)
Represents a DOM element.
|
Field Attributes | Field Name and Description |
---|---|
<static> |
webdriver.WebElement.ELEMENT_KEY
The property key used in the wire protocol to indicate that a JSON object
contains the ID of a WebElement.
|
Method Attributes | Method Name and Description |
---|---|
clear()
Schedules a command to clear the {@code value} of this element.
|
|
click()
Schedules a command to click on this element.
|
|
<static> |
webdriver.WebElement.equals(a, b)
Compares to WebElements for equality.
|
findElement(locator, var_args)
Schedule a command to find a descendant of this element.
|
|
findElements(locator, var_args)
Schedules a command to find all of the descendants of this element that match
the given search criteria.
|
|
getAttribute(attributeName)
Schedules a command to query for the value of the given attribute of the
element.
|
|
getCssValue(cssStyleProperty)
Schedules a command to query for the computed style of the element
represented by this instance.
|
|
Schedules a command to retrieve the inner HTML of this element.
|
|
Schedules a command to compute the location of this element in page space.
|
|
Schedules a command to retrieve the outer HTML of this element.
|
|
getSize()
Schedules a command to compute the size of this element's bounding box, in
pixels.
|
|
Schedules a command to query for the tag/node name of this element.
|
|
getText()
Get the visible (i.e.
|
|
Schedules a command to test whether this element is currently displayed.
|
|
isElementPresent(locator, var_args)
Schedules a command to test if there is at least one descendant of this
element that matches the given search criteria.
|
|
Schedules a command to query whether the DOM element represented by this
instance is enabled, as dicted by the {@code disabled} attribute.
|
|
Schedules a command to query whether this element is selected.
|
|
sendKeys(var_args)
Schedules a command to type a sequence on the DOM element represented by this
instance.
|
|
submit()
Schedules a command to submit the form containing this element (or this
element if it is a FORM element).
|
|
driver.get('http://www.google.com');
var searchForm = driver.findElement(By.tagName('form'));
var searchBox = searchForm.findElement(By.name('q'));
searchBox.sendKeys('webdriver');
The WebElement is implemented as a promise for compatibility with the promise
API. It will always resolve itself when its internal state has been fully
resolved and commands may be issued against the element. This can be used to
catch errors when an element cannot be located on the page:
driver.findElement(By.id('not-there')).then(function(element) {
alert('Found an element that was not expected to be there!');
}, function(error) {
alert('The element was not found, as expected');
});
- Parameters:
- {!webdriver.WebDriver} driver
- The parent WebDriver instance for this element.
- {!(string|webdriver.promise.Promise)} id
- Either the opaque ID for the underlying DOM element assigned by the server, or a promise that will resolve to that ID or another WebElement.
- Returns:
- {!webdriver.promise.Promise} A promise that will be resolved when the element has been cleared.
- Returns:
- {!webdriver.promise.Promise} A promise that will be resolved when the click command has completed.
- Parameters:
- {!webdriver.WebElement} a
- A WebElement.
- {!webdriver.WebElement} b
- A WebElement.
- Returns:
- {!webdriver.promise.Promise} A promise that will be resolved to whether the two WebElements are equal.
var e1 = element.findElement(By.id('foo'));
var e2 = element.findElement({id:'foo'});
Note that JS locator searches cannot be restricted to a subtree. All such
searches are delegated to this instance's parent WebDriver.
- Parameters:
-
{webdriver.Locator|Object.
} locator - The locator strategy to use when searching for the element.
- {...} var_args
- Arguments to pass to {@code WebDriver#executeScript} if using a JavaScript locator. Otherwise ignored.
- Returns:
- {webdriver.WebElement} A WebElement that can be used to issue commands against the located element. If the element is not found, the element will be invalidated and all scheduled commands aborted.
- Parameters:
-
{webdriver.Locator|Object.
} locator - The locator strategy to use when searching for the elements.
- {...} var_args
- Arguments to pass to {@code WebDriver#executeScript} if using a JavaScript locator. Otherwise ignored.
- Returns:
- {!webdriver.promise.Promise} A promise that will be resolved with an array of located webdriver.WebElements.
async, autofocus, autoplay, checked, compact, complete, controls, declare, defaultchecked, defaultselected, defer, disabled, draggable, ended, formnovalidate, hidden, indeterminate, iscontenteditable, ismap, itemscope, loop, multiple, muted, nohref, noresize, noshade, novalidate, nowrap, open, paused, pubdate, readonly, required, reversed, scoped, seamless, seeking, selected, spellcheck, truespeed, willvalidate
Finally, the following commonly mis-capitalized attribute/property names are evaluated as expected:
- "class"
- "readonly"
- Parameters:
- {string} attributeName
- The name of the attribute to query.
- Returns:
- {!webdriver.promise.Promise} A promise that will be resolved with the attribute's value. The returned value will always be either a string or null.
- Parameters:
- {string} cssStyleProperty
- The name of the CSS style property to look up.
- Returns:
- {!webdriver.promise.Promise} A promise that will be resolved with the requested CSS value.
- Returns:
- {!webdriver.WebDriver} The parent driver for this instance.
- Returns:
- {!webdriver.promise.Promise} A promise that will be resolved with the element's inner HTML.
- Returns:
- {!webdriver.promise.Promise} A promise that will be resolved to the element's location as a {@code {x:number, y:number}} object.
- Returns:
- {!webdriver.promise.Promise} A promise that will be resolved with the element's outer HTML.
- Returns:
- {!webdriver.promise.Promise} A promise that will be resolved with the element's size as a {@code {width:number, height:number}} object.
- Returns:
- {!webdriver.promise.Promise} A promise that will be resolved with the element's tag name.
- Returns:
- {!webdriver.promise.Promise} A promise that will be resolved with the element's visible text.
- Returns:
- {!webdriver.promise.Promise} A promise that will be resolved with whether this element is currently visible on the page.
Note that JS locator searches cannot be restricted to a subtree of the DOM. All such searches are delegated to this instance's parent WebDriver.
- Parameters:
-
{webdriver.Locator|Object.
} locator - The locator strategy to use when searching for the element.
- {...} var_args
- Arguments to pass to {@code WebDriver#executeScript} if using a JavaScript locator. Otherwise ignored.
- Returns:
- {!webdriver.promise.Promise} A promise that will be resolved with whether an element could be located on the page.
- Returns:
- {!webdriver.promise.Promise} A promise that will be resolved with whether this element is currently enabled.
- Returns:
- {!webdriver.promise.Promise} A promise that will be resolved with whether this element is currently selected.
- The modifier key is encountered again in the sequence. At this point the state of the key is toggled (along with the appropriate keyup/down events).
- The {@code webdriver.Key.NULL} key is encountered in the sequence. When
this key is encountered, all modifier keys current in the down state are
released (with accompanying keyup events). The NULL key can be used to
simulate common keyboard shortcuts:
element.sendKeys("text was", webdriver.Key.CONTROL, "a", webdriver.Key.NULL, "now text is"); // Alternatively: element.sendKeys("text was", webdriver.Key.chord(webdriver.Key.CONTROL, "a"), "now text is");
- The end of the keysequence is encountered. When there are no more keys to type, all depressed modifier keys are released (with accompanying keyup events).
- Parameters:
- {...string} var_args
- The sequence of keys to type. All arguments will be joined into a single sequence (var_args is permitted for convenience).
- Returns:
- {!webdriver.promise.Promise} A promise that will be resolved when all keys have been typed.
- Returns:
- {!webdriver.promise.Promise} A promise that will be resolved when the form has been submitted.
- Returns:
- {!webdriver.promise.Promise} A promise that resolves to this element's JSON representation as defined by the WebDriver wire protocol.
- See:
- http://code.google.com/p/selenium/wiki/JsonWireProtocol