selenium-webdriver
Version:
The official WebDriver JavaScript bindings from the Selenium project
216 lines (215 loc) • 30.6 kB
HTML
<meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no"><meta http-equiv="Content-Language" content="en"><meta http-equiv="X-UA-Compatible" content="IE=edge"><title>WebElement</title><link href="dossier.css" rel="stylesheet" type="text/css"><header><div><form><div><input type="search" placeholder="Search" tabindex="1"></div></form></div></header><main><article><div class="parentlink"><b>Module:</b> <a href="module_selenium-webdriver.html">selenium-webdriver</a></div><div class="codelink"><a href="source/index.js.src.html#l74">View Source</a></div><h1>class WebElement</h1><pre class="inheritance"><a href="class_webdriver_Serializable.html">webdriver.Serializable</a><{ELEMENT: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">string</a>}>
└ WebElement</pre><dl><dt>Alias for <code><a href="class_webdriver_WebElement.html">webdriver.WebElement</a></code></dl><p>Represents a DOM element. WebElements can be found by searching from the
document root using a <a href="class_webdriver_WebDriver.html"><code>webdriver.WebDriver</code></a> instance, or by searching
under another WebElement:</p>
<pre><code>driver.get('http://www.google.com');
var searchForm = driver.findElement(By.tagName('form'));
var searchBox = searchForm.findElement(By.name('q'));
searchBox.sendKeys('webdriver');
</code></pre>
<p>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:</p>
<pre><code>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');
});
</code></pre>
<h3>new WebElement(<wbr>driver, id)</h3><div><div class="fn-details"><div><b>Parameters</b></div><dl><dt>driver<code><a href="class_webdriver_WebDriver.html">webdriver.WebDriver</a></code><dd><p>The parent WebDriver instance for this
element.</p>
<dt>id<code>(<a href="class_webdriver_promise_Promise.html">webdriver.promise.Promise</a><{ELEMENT: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">string</a>}>|{ELEMENT: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">string</a>})</code><dd><p>The server-assigned opaque ID for the
underlying DOM element.</p>
</dl></div></div><h2>Instance Methods</h2><div id="clear" class="function"><div><h3>clear()<span class="codelink"><a href="source/lib/webdriver/webdriver.js.src.html#l2171">code »</a></span></h3><p>Schedules a command to clear the <code>value</code> of this element. This command
has no effect if the underlying DOM element is neither a text INPUT element
nor a TEXTAREA element.</p>
<div><div class="fn-details"><div><b>Returns</b></div><dl><dt><code><a href="class_webdriver_promise_Promise.html">webdriver.promise.Promise</a><<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Undefined">undefined</a>></code><dd><p>A promise that will be resolved
when the element has been cleared.</p>
</dl></div></div></div></div><hr class="fn-sep"><div id="click" class="function"><div><h3>click()<span class="codelink"><a href="source/lib/webdriver/webdriver.js.src.html#l1919">code »</a></span></h3><p>Schedules a command to click on this element.</p>
<div><div class="fn-details"><div><b>Returns</b></div><dl><dt><code><a href="class_webdriver_promise_Promise.html">webdriver.promise.Promise</a><<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Undefined">undefined</a>></code><dd><p>A promise that will be resolved
when the click command has completed.</p>
</dl></div></div></div></div><hr class="fn-sep"><div id="findElement" class="function"><div><h3>findElement(<wbr>locator)<span class="codelink"><a href="source/lib/webdriver/webdriver.js.src.html#l1859">code »</a></span></h3><p>Schedule a command to find a descendant of this element. If the element
cannot be found, a <a href="enum_bot_ErrorCode.html#NO_SUCH_ELEMENT"><code>bot.ErrorCode.NO_SUCH_ELEMENT</code></a> result will
be returned by the driver. Unlike other commands, this error cannot be
suppressed. In other words, scheduling a command to find an element doubles
as an assert that the element is present on the page. To test whether an
element is present on the page, use <a href="module_selenium-webdriver_class_WebElement.html#isElementPresent"><code>#isElementPresent</code></a> instead.</p>
<p>The search criteria for an element may be defined using one of the
factories in the <a href="namespace_webdriver_By.html"><code>webdriver.By</code></a> namespace, or as a short-hand
<a href="namespace_webdriver_By.html#By.Hash"><code>webdriver.By.Hash</code></a> object. For example, the following two statements
are equivalent:</p>
<pre><code>var e1 = element.findElement(By.id('foo'));
var e2 = element.findElement({id:'foo'});
</code></pre>
<p>You may also provide a custom locator function, which takes as input
this WebDriver instance and returns a <a href="class_webdriver_WebElement.html"><code>webdriver.WebElement</code></a>, or a
promise that will resolve to a WebElement. For example, to find the first
visible link on a page, you could write:</p>
<pre><code>var link = element.findElement(firstVisibleLink);
function firstVisibleLink(element) {
var links = element.findElements(By.tagName('a'));
return webdriver.promise.filter(links, function(link) {
return links.isDisplayed();
}).then(function(visibleLinks) {
return visibleLinks[0];
});
}
</code></pre>
<div><div class="fn-details"><div><b>Parameters</b></div><dl><dt>locator<code>(<a href="class_webdriver_Locator.html">webdriver.Locator</a>|{className: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">string</a>}|{css: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">string</a>}|{id: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">string</a>}|{js: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">string</a>}|{linkText: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">string</a>}|{name: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">string</a>}|{partialLinkText: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">string</a>}|{tagName: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">string</a>}|{xpath: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">string</a>})</code><dd><p>The
locator strategy to use when searching for the element.</p>
</dl></div><div class="fn-details"><div><b>Returns</b></div><dl><dt><code><a href="class_webdriver_WebElement.html">webdriver.WebElement</a></code><dd><p>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.</p>
</dl></div></div></div></div><hr class="fn-sep"><div id="findElements" class="function"><div><h3>findElements(<wbr>locator)<span class="codelink"><a href="source/lib/webdriver/webdriver.js.src.html#l1900">code »</a></span></h3><p>Schedules a command to find all of the descendants of this element that
match the given search criteria.</p>
<div><div class="fn-details"><div><b>Parameters</b></div><dl><dt>locator<code>(<a href="class_webdriver_Locator.html">webdriver.Locator</a>|{className: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">string</a>}|{css: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">string</a>}|{id: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">string</a>}|{js: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">string</a>}|{linkText: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">string</a>}|{name: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">string</a>}|{partialLinkText: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">string</a>}|{tagName: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">string</a>}|{xpath: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">string</a>})</code><dd><p>The
locator strategy to use when searching for the elements.</p>
</dl></div><div class="fn-details"><div><b>Returns</b></div><dl><dt><code><a href="class_webdriver_promise_Promise.html">webdriver.promise.Promise</a><<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array">Array</a><<a href="class_webdriver_WebElement.html">webdriver.WebElement</a>>></code><dd><p>A
promise that will resolve to an array of WebElements.</p>
</dl></div></div></div></div><hr class="fn-sep"><div id="getAttribute" class="function"><div><h3>getAttribute(<wbr>attributeName)<span class="codelink"><a href="source/lib/webdriver/webdriver.js.src.html#l2077">code »</a></span></h3><p>Schedules a command to query for the value of the given attribute of the
element. Will return the current value, even if it has been modified after
the page has been loaded. More exactly, this method will return the value of
the given attribute, unless that attribute is not present, in which case the
value of the property with the same name is returned. If neither value is
set, null is returned (for example, the "value" property of a textarea
element). The "style" attribute is converted as best can be to a
text representation with a trailing semi-colon. The following are deemed to
be "boolean" attributes and will return either "true" or null:</p>
<p>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</p>
<p>Finally, the following commonly mis-capitalized attribute/property names
are evaluated as expected:</p>
<ul><li>"class"</li><li>"readonly"</li></ul>
<div><div class="fn-details"><div><b>Parameters</b></div><dl><dt>attributeName<code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">string</a></code><dd><p>The name of the attribute to query.</p>
</dl></div><div class="fn-details"><div><b>Returns</b></div><dl><dt><code><a href="class_webdriver_promise_Promise.html">webdriver.promise.Promise</a><?<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">string</a>></code><dd><p>A promise that will be
resolved with the attribute's value. The returned value will always be
either a string or null.</p>
</dl></div></div></div></div><hr class="fn-sep"><div id="getCssValue" class="function"><div><h3>getCssValue(<wbr>cssStyleProperty)<span class="codelink"><a href="source/lib/webdriver/webdriver.js.src.html#l2039">code »</a></span></h3><p>Schedules a command to query for the computed style of the element
represented by this instance. If the element inherits the named style from
its parent, the parent will be queried for its value. Where possible, color
values will be converted to their hex representation (e.g. #00ff00 instead of
rgb(0, 255, 0)).</p>
<p><em>Warning:</em> the value returned will be as the browser interprets it, so
it may be tricky to form a proper assertion.</p>
<div><div class="fn-details"><div><b>Parameters</b></div><dl><dt>cssStyleProperty<code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">string</a></code><dd><p>The name of the CSS style property to look
up.</p>
</dl></div><div class="fn-details"><div><b>Returns</b></div><dl><dt><code><a href="class_webdriver_promise_Promise.html">webdriver.promise.Promise</a><<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">string</a>></code><dd><p>A promise that will be
resolved with the requested CSS value.</p>
</dl></div></div></div></div><hr class="fn-sep"><div id="getDriver" class="function"><div><h3>getDriver()<span class="codelink"><a href="source/lib/webdriver/webdriver.js.src.html#l1768">code »</a></span></h3><div><div class="fn-details"><div><b>Returns</b></div><dl><dt><code><a href="class_webdriver_WebDriver.html">webdriver.WebDriver</a></code><dd><p>The parent driver for this instance.</p>
</dl></div></div></div></div><hr class="fn-sep"><div id="getId" class="function"><div><h3>getId()<span class="codelink"><a href="source/lib/webdriver/webdriver.js.src.html#l1779">code »</a></span></h3><div><div class="fn-details"><div><b>Returns</b></div><dl><dt><code><a href="class_webdriver_promise_Promise.html">webdriver.promise.Promise</a><{ELEMENT: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">string</a>}></code><dd><p>A promise
that resolves to this element's JSON representation as defined by the
WebDriver wire protocol.</p>
</dl></div></div></div></div><hr class="fn-sep"><div id="getInnerHtml" class="function"><div><h3>getInnerHtml()<span class="codelink"><a href="source/lib/webdriver/webdriver.js.src.html#l2214">code »</a></span></h3><p>Schedules a command to retrieve the inner HTML of this element.</p>
<div><div class="fn-details"><div><b>Returns</b></div><dl><dt><code><a href="class_webdriver_promise_Promise.html">webdriver.promise.Promise</a><<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">string</a>></code><dd><p>A promise that will be
resolved with the element's inner HTML.</p>
</dl></div></div></div></div><hr class="fn-sep"><div id="getLocation" class="function"><div><h3>getLocation()<span class="codelink"><a href="source/lib/webdriver/webdriver.js.src.html#l2118">code »</a></span></h3><p>Schedules a command to compute the location of this element in page space.</p>
<div><div class="fn-details"><div><b>Returns</b></div><dl><dt><code><a href="class_webdriver_promise_Promise.html">webdriver.promise.Promise</a><{x: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number">number</a>, y: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number">number</a>}></code><dd><p>A promise that
will be resolved to the element's location as a
<code>{x:number, y:number}</code> object.</p>
</dl></div></div></div></div><hr class="fn-sep"><div id="getOuterHtml" class="function"><div><h3>getOuterHtml()<span class="codelink"><a href="source/lib/webdriver/webdriver.js.src.html#l2195">code »</a></span></h3><p>Schedules a command to retrieve the outer HTML of this element.</p>
<div><div class="fn-details"><div><b>Returns</b></div><dl><dt><code><a href="class_webdriver_promise_Promise.html">webdriver.promise.Promise</a><<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">string</a>></code><dd><p>A promise that will be
resolved with the element's outer HTML.</p>
</dl></div></div></div></div><hr class="fn-sep"><div id="getRawId" class="function"><div><h3>getRawId()<span class="codelink"><a href="source/lib/webdriver/webdriver.js.src.html#l1790">code »</a></span></h3><p>Returns the raw ID string ID for this element.</p>
<div><div class="fn-details"><div><b>Returns</b></div><dl><dt><code><a href="class_webdriver_promise_Promise.html">webdriver.promise.Promise</a><<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">string</a>></code><dd><p>A promise that resolves to this
element's raw ID as a string value.</p>
</dl></div></div></div></div><hr class="fn-sep"><div id="getSize" class="function"><div><h3>getSize()<span class="codelink"><a href="source/lib/webdriver/webdriver.js.src.html#l2105">code »</a></span></h3><p>Schedules a command to compute the size of this element's bounding box, in
pixels.</p>
<div><div class="fn-details"><div><b>Returns</b></div><dl><dt><code><a href="class_webdriver_promise_Promise.html">webdriver.promise.Promise</a><{height: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number">number</a>, width: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number">number</a>}></code><dd><p>A
promise that will be resolved with the element's size as a
<code>{width:number, height:number}</code> object.</p>
</dl></div></div></div></div><hr class="fn-sep"><div id="getTagName" class="function"><div><h3>getTagName()<span class="codelink"><a href="source/lib/webdriver/webdriver.js.src.html#l2017">code »</a></span></h3><p>Schedules a command to query for the tag/node name of this element.</p>
<div><div class="fn-details"><div><b>Returns</b></div><dl><dt><code><a href="class_webdriver_promise_Promise.html">webdriver.promise.Promise</a><<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">string</a>></code><dd><p>A promise that will be
resolved with the element's tag name.</p>
</dl></div></div></div></div><hr class="fn-sep"><div id="getText" class="function"><div><h3>getText()<span class="codelink"><a href="source/lib/webdriver/webdriver.js.src.html#l2091">code »</a></span></h3><p>Get the visible (i.e. not hidden by CSS) innerText of this element, including
sub-elements, without any leading or trailing whitespace.</p>
<div><div class="fn-details"><div><b>Returns</b></div><dl><dt><code><a href="class_webdriver_promise_Promise.html">webdriver.promise.Promise</a><<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">string</a>></code><dd><p>A promise that will be
resolved with the element's visible text.</p>
</dl></div></div></div></div><hr class="fn-sep"><div id="isDisplayed" class="function"><div><h3>isDisplayed()<span class="codelink"><a href="source/lib/webdriver/webdriver.js.src.html#l2183">code »</a></span></h3><p>Schedules a command to test whether this element is currently displayed.</p>
<div><div class="fn-details"><div><b>Returns</b></div><dl><dt><code><a href="class_webdriver_promise_Promise.html">webdriver.promise.Promise</a><<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean">boolean</a>></code><dd><p>A promise that will be
resolved with whether this element is currently visible on the page.</p>
</dl></div></div></div></div><hr class="fn-sep"><div id="isElementPresent" class="function"><div><h3>isElementPresent(<wbr>locator)<span class="codelink"><a href="source/lib/webdriver/webdriver.js.src.html#l1884">code »</a></span></h3><p>Schedules a command to test if there is at least one descendant of this
element that matches the given search criteria.</p>
<div><div class="fn-details"><div><b>Parameters</b></div><dl><dt>locator<code>(<a href="class_webdriver_Locator.html">webdriver.Locator</a>|{className: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">string</a>}|{css: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">string</a>}|{id: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">string</a>}|{js: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">string</a>}|{linkText: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">string</a>}|{name: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">string</a>}|{partialLinkText: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">string</a>}|{tagName: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">string</a>}|{xpath: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">string</a>})</code><dd><p>The
locator strategy to use when searching for the element.</p>
</dl></div><div class="fn-details"><div><b>Returns</b></div><dl><dt><code><a href="class_webdriver_promise_Promise.html">webdriver.promise.Promise</a><<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean">boolean</a>></code><dd><p>A promise that will be
resolved with whether an element could be located on the page.</p>
</dl></div></div></div></div><hr class="fn-sep"><div id="isEnabled" class="function"><div><h3>isEnabled()<span class="codelink"><a href="source/lib/webdriver/webdriver.js.src.html#l2131">code »</a></span></h3><p>Schedules a command to query whether the DOM element represented by this
instance is enabled, as dicted by the <code>disabled</code> attribute.</p>
<div><div class="fn-details"><div><b>Returns</b></div><dl><dt><code><a href="class_webdriver_promise_Promise.html">webdriver.promise.Promise</a><<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean">boolean</a>></code><dd><p>A promise that will be
resolved with whether this element is currently enabled.</p>
</dl></div></div></div></div><hr class="fn-sep"><div id="isSelected" class="function"><div><h3>isSelected()<span class="codelink"><a href="source/lib/webdriver/webdriver.js.src.html#l2143">code »</a></span></h3><p>Schedules a command to query whether this element is selected.</p>
<div><div class="fn-details"><div><b>Returns</b></div><dl><dt><code><a href="class_webdriver_promise_Promise.html">webdriver.promise.Promise</a><<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean">boolean</a>></code><dd><p>A promise that will be
resolved with whether this element is currently selected.</p>
</dl></div></div></div></div><hr class="fn-sep"><div id="sendKeys" class="function"><div><h3>sendKeys(<wbr>var_args)<span class="codelink"><a href="source/lib/webdriver/webdriver.js.src.html#l1979">code »</a></span></h3><p>Schedules a command to type a sequence on the DOM element represented by this
instance.</p>
<p>Modifier keys (SHIFT, CONTROL, ALT, META) are stateful; once a modifier is
processed in the keysequence, that key state is toggled until one of the
following occurs:</p>
<ul><li>
<p>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).</p>
</li><li>
<p>The <a href="enum_webdriver_Key.html#NULL"><code>webdriver.Key.NULL</code></a> 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:</p>
<pre><code> 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");
</code></pre>
</li><li>
<p>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).</p>
</li></ul>
<p>If this element is a file input (<code><input type="file"></code>), the
specified key sequence should specify the path to the file to attach to
the element. This is analgous to the user clicking "Browse..." and entering
the path into the file select dialog.</p>
<pre><code>var form = driver.findElement(By.css('form'));
var element = form.findElement(By.css('input[type=file]'));
element.sendKeys('/path/to/file.txt');
form.submit();
</code></pre>
<p>For uploads to function correctly, the entered path must reference a file
on the <em>browser's</em> machine, not the local machine running this script. When
running against a remote Selenium server, a <a href="class_webdriver_FileDetector.html"><code>webdriver.FileDetector</code></a>
may be used to transparently copy files to the remote machine before
attempting to upload them in the browser.</p>
<p><strong>Note:</strong> On browsers where native keyboard events are not supported
(e.g. Firefox on OS X), key events will be synthesized. Special
punctionation keys will be synthesized according to a standard QWERTY en-us
keyboard layout.</p>
<div><div class="fn-details"><div><b>Parameters</b></div><dl><dt>var_args<code>...(<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">string</a>|<a href="class_webdriver_promise_Promise.html">webdriver.promise.Promise</a><<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">string</a>>)</code><dd><p>The sequence
of keys to type. All arguments will be joined into a single sequence.</p>
</dl></div><div class="fn-details"><div><b>Returns</b></div><dl><dt><code><a href="class_webdriver_promise_Promise.html">webdriver.promise.Promise</a><<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Undefined">undefined</a>></code><dd><p>A promise that will be resolved
when all keys have been typed.</p>
</dl></div></div></div></div><hr class="fn-sep"><div id="serialize" class="function"><div><h3>serialize()<span class="codelink"><a href="source/lib/webdriver/webdriver.js.src.html#l1798">code »</a></span></h3><p>Returns either this instance's serialized represention, if immediately
available, or a promise for its serialized representation. This function is
conceptually equivalent to objects that have a <code>toJSON()</code> property,
except the serialize() result may be a promise or an object containing a
promise (which are not directly JSON friendly).</p>
<p><b>Overrides: </b><a href="class_webdriver_Serializable.html#serialize">webdriver.Serializable</a></p><div><div class="fn-details"><div><b>Returns</b></div><dl><dt><code>(<a href="class_webdriver_WebElement.html#WebElement.Id">webdriver.WebElement.Id</a>|IThenable<<a href="class_webdriver_WebElement.html#WebElement.Id">webdriver.WebElement.Id</a>>)</code><dd><p>This instance's serialized wire format.</p>
</dl></div></div></div></div><hr class="fn-sep"><div id="submit" class="function"><div><h3>submit()<span class="codelink"><a href="source/lib/webdriver/webdriver.js.src.html#l2157">code »</a></span></h3><p>Schedules a command to submit the form containing this element (or this
element if it is a FORM element). This command is a no-op if the element is
not contained in a form.</p>
<div><div class="fn-details"><div><b>Returns</b></div><dl><dt><code><a href="class_webdriver_promise_Promise.html">webdriver.promise.Promise</a><<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Undefined">undefined</a>></code><dd><p>A promise that will be resolved
when the form has been submitted.</p>
</dl></div></div></div></div><h2>Static Functions</h2><div id="WebElement.equals" class="function"><div><h3>WebElement.equals(<wbr>a, b)<span class="codelink"><a href="source/lib/webdriver/webdriver.js.src.html#l1743">code »</a></span></h3><p>Compares to WebElements for equality.</p>
<div><div class="fn-details"><div><b>Parameters</b></div><dl><dt>a<code><a href="class_webdriver_WebElement.html">webdriver.WebElement</a></code><dd><p>A WebElement.</p>
<dt>b<code><a href="class_webdriver_WebElement.html">webdriver.WebElement</a></code><dd><p>A WebElement.</p>
</dl></div><div class="fn-details"><div><b>Returns</b></div><dl><dt><code><a href="class_webdriver_promise_Promise.html">webdriver.promise.Promise</a><<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean">boolean</a>></code><dd><p>A promise that will be
resolved to whether the two WebElements are equal.</p>
</dl></div></div></div></div><h2>Static Properties</h2><div id="WebElement.ELEMENT_KEY" class="property"><dl><dt><a href="source/lib/webdriver/webdriver.js.src.html#l1733">WebElement.ELEMENT_KEY</a><code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">string</a></code><dd><p>The property key used in the wire protocol to indicate that a JSON object
contains the ID of a WebElement.</p>
</dl></div><h2>Type Definitions</h2><div id="WebElement.Id" class="property"><dl><dt><a href="source/lib/webdriver/webdriver.js.src.html#l1724">WebElement.Id</a><code>{ELEMENT: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">string</a>}</code><dd><p>Wire protocol definition of a WebElement ID.</p>
</dl></div></article><nav><h3><a href="index.html" tabindex="2">Overview</a></h3><div><input type="checkbox" id="nav-modules" checked/><label for="nav-modules"><h3><span class="selectable" tabindex="2">Modules</span></h3></label><div id="nav-modules-view"></div></div><div><input type="checkbox" id="nav-types" checked/><label for="nav-types"><h3><span class="selectable" tabindex="2">Types</span></h3></label><div id="nav-types-view"></div></div><h3><a href="Changes.html" tabindex="2">Changes</a></h3></nav></main><footer><div><a href="https://github.com/jleyba/js-dossier">Generated by dossier</a></div></footer><script src="types.js"></script><script src="dossier.js"></script>