UNPKG

selenium-webdriver

Version:

The official WebDriver JavaScript bindings from the Selenium project

280 lines (279 loc) 38.3 kB
<!DOCTYPE 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>Driver</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_chrome.html">selenium-webdriver/chrome</a></div><div class="codelink"><a href="source/chrome.js.src.html#l844">View Source</a></div><h1>class Driver</h1><pre class="inheritance"><a href="class_webdriver_WebDriver.html">webdriver.WebDriver</a> &#x2514; Driver</pre><p>Creates a new WebDriver client for Chrome.</p> <h3>new Driver(<wbr>opt_config, opt_service, opt_flow)</h3><div><div class="fn-details"><div><b>Parameters</b></div><dl><dt>opt_config<code>?(<a href="module_selenium-webdriver_class_Capabilities.html">Capabilities</a>|<a href="module_selenium-webdriver_chrome_class_Options.html">Options</a>)=</code><dd><p>The configuration options.</p> <dt>opt_service<code>?<a href="module_selenium-webdriver_remote_class_DriverService.html">DriverService</a>=</code><dd><p>The session to use; will use the default service by default.</p> <dt>opt_flow<code>?<a href="class_webdriver_promise_ControlFlow.html">webdriver.promise.ControlFlow</a>=</code><dd><p>The control flow to use, or <code>null</code> to use the currently active flow.</p> </dl></div></div><h2>Instance Methods</h2><div id="actions" class="function"><div><h3>actions()<span class="codelink"><a href="source/lib/webdriver/webdriver.js.src.html#l469">code »</a></span></h3><p>Creates a new action sequence using this driver. The sequence will not be scheduled for execution until <a href="class_webdriver_ActionSequence.html#perform"><code>webdriver.ActionSequence#perform</code></a> is called. Example:</p> <pre><code>driver.actions(). mouseDown(element1). mouseMove(element2). mouseUp(). perform(); </code></pre> <p><b>Defined by: </b><a href="class_webdriver_WebDriver.html#actions">webdriver.WebDriver</a></p><div><div class="fn-details"><div><b>Returns</b></div><dl><dt><code><a href="class_webdriver_ActionSequence.html">webdriver.ActionSequence</a></code><dd><p>A new action sequence for this instance.</p> </dl></div></div></div></div><hr class="fn-sep"><div id="call" class="function"><div><h3><code>&lt;T&gt;</code> call(<wbr>fn, opt_scope, var_args)<span class="codelink"><a href="source/lib/webdriver/webdriver.js.src.html#l639">code »</a></span></h3><p>Schedules a command to execute a custom function.</p> <p><b>Defined by: </b><a href="class_webdriver_WebDriver.html#call">webdriver.WebDriver</a></p><div><div class="fn-details"><div><b>Parameters</b></div><dl><dt>fn<code>function(...?): (T|<a href="class_webdriver_promise_Promise.html">webdriver.promise.Promise</a>&lt;T&gt;)</code><dd><p>The function to execute.</p> <dt>opt_scope<code>?<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object">Object</a>=</code><dd><p>The object in whose scope to execute the function.</p> <dt>var_args<code>...*</code><dd><p>Any arguments to pass to the function.</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>&lt;T&gt;</code><dd><p>A promise that will be resolved&#39; with the function&#39;s result.</p> </dl></div></div></div></div><hr class="fn-sep"><div id="close" class="function"><div><h3>close()<span class="codelink"><a href="source/lib/webdriver/webdriver.js.src.html#l780">code »</a></span></h3><p>Schedules a command to close the current window.</p> <p><b>Defined by: </b><a href="class_webdriver_WebDriver.html#close">webdriver.WebDriver</a></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>&lt;<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Undefined">undefined</a>&gt;</code><dd><p>A promise that will be resolved when this command has completed.</p> </dl></div></div></div></div><hr class="fn-sep"><div id="controlFlow" class="function"><div><h3>controlFlow()<span class="codelink"><a href="source/lib/webdriver/webdriver.js.src.html#l324">code »</a></span></h3><p><b>Defined by: </b><a href="class_webdriver_WebDriver.html#controlFlow">webdriver.WebDriver</a></p><div><div class="fn-details"><div><b>Returns</b></div><dl><dt><code><a href="class_webdriver_promise_ControlFlow.html">webdriver.promise.ControlFlow</a></code><dd><p>The control flow used by this instance.</p> </dl></div></div></div></div><hr class="fn-sep"><div id="executeAsyncScript" class="function"><div><h3><code>&lt;T&gt;</code> executeAsyncScript(<wbr>script, var_args)<span class="codelink"><a href="source/lib/webdriver/webdriver.js.src.html#l617">code »</a></span></h3><p>Schedules a command to execute asynchronous JavaScript in the context of the currently selected frame or window. The script fragment will be executed as the body of an anonymous function. If the script is provided as a function object, that function will be converted to a string for injection into the target window.</p> <p>Any arguments provided in addition to the script will be included as script arguments and may be referenced using the <code>arguments</code> object. Arguments may be a boolean, number, string, or <code>webdriver.WebElement</code>. Arrays and objects may also be used as script arguments as long as each item adheres to the types previously mentioned.</p> <p>Unlike executing synchronous JavaScript with <a href="module_selenium-webdriver_chrome_class_Driver.html#executeScript"><code>#executeScript</code></a>, scripts executed with this function must explicitly signal they are finished by invoking the provided callback. This callback will always be injected into the executed function as the last argument, and thus may be referenced with <code>arguments[arguments.length - 1]</code>. The following steps will be taken for resolving this functions return value against the first argument to the script&#39;s callback function:</p> <ul><li>For a HTML element, the value will resolve to a <a href="class_webdriver_WebElement.html"><code>webdriver.WebElement</code></a></li><li>Null and undefined return values will resolve to null</li><li>Booleans, numbers, and strings will resolve as is</li><li>Functions will resolve to their string representation</li><li>For arrays and objects, each member item will be converted according to the rules above</li></ul> <p><strong>Example #1:</strong> Performing a sleep that is synchronized with the currently selected window:</p> <pre><code>var start &#61; new Date().getTime(); driver.executeAsyncScript( &#39;window.setTimeout(arguments[arguments.length - 1], 500);&#39;). then(function() { console.log( &#39;Elapsed time: &#39; &#43; (new Date().getTime() - start) &#43; &#39; ms&#39;); }); </code></pre> <p><strong>Example #2:</strong> Synchronizing a test with an AJAX application:</p> <pre><code>var button &#61; driver.findElement(By.id(&#39;compose-button&#39;)); button.click(); driver.executeAsyncScript( &#39;var callback &#61; arguments[arguments.length - 1];&#39; &#43; &#39;mailClient.getComposeWindowWidget().onload(callback);&#39;); driver.switchTo().frame(&#39;composeWidget&#39;); driver.findElement(By.id(&#39;to&#39;)).sendKeys(&#39;dog&#64;example.com&#39;); </code></pre> <p><strong>Example #3:</strong> Injecting a XMLHttpRequest and waiting for the result. In this example, the inject script is specified with a function literal. When using this format, the function is converted to a string for injection, so it should not reference any symbols not defined in the scope of the page under test.</p> <pre><code>driver.executeAsyncScript(function() { var callback &#61; arguments[arguments.length - 1]; var xhr &#61; new XMLHttpRequest(); xhr.open(&#34;GET&#34;, &#34;/resource/data.json&#34;, true); xhr.onreadystatechange &#61; function() { if (xhr.readyState &#61;&#61; 4) { callback(xhr.responseText); } } xhr.send(&#39;&#39;); }).then(function(str) { console.log(JSON.parse(str)[&#39;food&#39;]); }); </code></pre> <p><b>Defined by: </b><a href="class_webdriver_WebDriver.html#executeAsyncScript">webdriver.WebDriver</a></p><div><div class="fn-details"><div><b>Parameters</b></div><dl><dt>script<code>(<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">string</a>|Function)</code><dd><p>The script to execute.</p> <dt>var_args<code>...*</code><dd><p>The arguments to pass to the script.</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>&lt;T&gt;</code><dd><p>A promise that will resolve to the scripts return value.</p> </dl></div></div></div></div><hr class="fn-sep"><div id="executeScript" class="function"><div><h3><code>&lt;T&gt;</code> executeScript(<wbr>script, var_args)<span class="codelink"><a href="source/lib/webdriver/webdriver.js.src.html#l528">code »</a></span></h3><p>Schedules a command to execute JavaScript in the context of the currently selected frame or window. The script fragment will be executed as the body of an anonymous function. If the script is provided as a function object, that function will be converted to a string for injection into the target window.</p> <p>Any arguments provided in addition to the script will be included as script arguments and may be referenced using the <code>arguments</code> object. Arguments may be a boolean, number, string, or <code>webdriver.WebElement</code>. Arrays and objects may also be used as script arguments as long as each item adheres to the types previously mentioned.</p> <p>The script may refer to any variables accessible from the current window. Furthermore, the script will execute in the window&#39;s context, thus <code>document</code> may be used to refer to the current document. Any local variables will not be available once the script has finished executing, though global variables will persist.</p> <p>If the script has a return value (i.e. if the script contains a return statement), then the following steps will be taken for resolving this functions return value:</p> <ul><li>For a HTML element, the value will resolve to a <a href="class_webdriver_WebElement.html"><code>webdriver.WebElement</code></a></li><li>Null and undefined return values will resolve to null</li><li>Booleans, numbers, and strings will resolve as is</li><li>Functions will resolve to their string representation</li><li>For arrays and objects, each member item will be converted according to the rules above</li></ul> <p><b>Defined by: </b><a href="class_webdriver_WebDriver.html#executeScript">webdriver.WebDriver</a></p><div><div class="fn-details"><div><b>Parameters</b></div><dl><dt>script<code>(<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">string</a>|Function)</code><dd><p>The script to execute.</p> <dt>var_args<code>...*</code><dd><p>The arguments to pass to the script.</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>&lt;T&gt;</code><dd><p>A promise that will resolve to the scripts return value.</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#l867">code »</a></span></h3><p>Schedule a command to find an element on the page. 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_chrome_class_Driver.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 &#61; driver.findElement(By.id(&#39;foo&#39;)); var e2 &#61; driver.findElement({id:&#39;foo&#39;}); </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 &#61; driver.findElement(firstVisibleLink); function firstVisibleLink(driver) { var links &#61; driver.findElements(By.tagName(&#39;a&#39;)); return webdriver.promise.filter(links, function(link) { return links.isDisplayed(); }).then(function(visibleLinks) { return visibleLinks[0]; }); } </code></pre> <p>When running in the browser, a WebDriver cannot manipulate DOM elements directly; it may do so only through a <a href="class_webdriver_WebElement.html"><code>webdriver.WebElement</code></a> reference. This function may be used to generate a WebElement from a DOM element. A reference to the DOM element will be stored in a known location and this driver will attempt to retrieve it through <a href="module_selenium-webdriver_chrome_class_Driver.html#executeScript"><code>#executeScript</code></a>. If the element cannot be found (eg, it belongs to a different document than the one this instance is currently focused on), a <a href="enum_bot_ErrorCode.html#NO_SUCH_ELEMENT"><code>bot.ErrorCode.NO_SUCH_ELEMENT</code></a> error will be returned.</p> <p><b>Defined by: </b><a href="class_webdriver_WebDriver.html#findElement">webdriver.WebDriver</a></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 to use.</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#l994">code »</a></span></h3><p>Schedule a command to search for multiple elements on the page.</p> <p><b>Defined by: </b><a href="class_webdriver_WebDriver.html#findElements">webdriver.WebDriver</a></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>&lt;<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array">Array</a>&lt;<a href="class_webdriver_WebElement.html">webdriver.WebElement</a>&gt;&gt;</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="get" class="function"><div><h3>get(<wbr>url)<span class="codelink"><a href="source/lib/webdriver/webdriver.js.src.html#l792">code »</a></span></h3><p>Schedules a command to navigate to the given URL.</p> <p><b>Defined by: </b><a href="class_webdriver_WebDriver.html#get">webdriver.WebDriver</a></p><div><div class="fn-details"><div><b>Parameters</b></div><dl><dt>url<code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">string</a></code><dd><p>The fully qualified URL to open.</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>&lt;<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Undefined">undefined</a>&gt;</code><dd><p>A promise that will be resolved when the document has finished loading.</p> </dl></div></div></div></div><hr class="fn-sep"><div id="getAllWindowHandles" class="function"><div><h3>getAllWindowHandles()<span class="codelink"><a href="source/lib/webdriver/webdriver.js.src.html#l753">code »</a></span></h3><p>Schedules a command to retrieve the current list of available window handles.</p> <p><b>Defined by: </b><a href="class_webdriver_WebDriver.html#getAllWindowHandles">webdriver.WebDriver</a></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>&lt;<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array">Array</a>&lt;<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">string</a>&gt;&gt;</code><dd><p>A promise that will be resolved with an array of window handles.</p> </dl></div></div></div></div><hr class="fn-sep"><div id="getCapabilities" class="function"><div><h3>getCapabilities()<span class="codelink"><a href="source/lib/webdriver/webdriver.js.src.html#l430">code »</a></span></h3><p><b>Defined by: </b><a href="class_webdriver_WebDriver.html#getCapabilities">webdriver.WebDriver</a></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>&lt;<a href="class_webdriver_Capabilities.html">webdriver.Capabilities</a>&gt;</code><dd><p>A promise that will resolve with the this instance&#39;s capabilities.</p> </dl></div></div></div></div><hr class="fn-sep"><div id="getCurrentUrl" class="function"><div><h3>getCurrentUrl()<span class="codelink"><a href="source/lib/webdriver/webdriver.js.src.html#l802">code »</a></span></h3><p>Schedules a command to retrieve the URL of the current page.</p> <p><b>Defined by: </b><a href="class_webdriver_WebDriver.html#getCurrentUrl">webdriver.WebDriver</a></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>&lt;<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">string</a>&gt;</code><dd><p>A promise that will be resolved with the current URL.</p> </dl></div></div></div></div><hr class="fn-sep"><div id="getPageSource" class="function"><div><h3>getPageSource()<span class="codelink"><a href="source/lib/webdriver/webdriver.js.src.html#l768">code »</a></span></h3><p>Schedules a command to retrieve the current page&#39;s source. The page source returned is a representation of the underlying DOM: do not expect it to be formatted or escaped in the same way as the response sent from the web server.</p> <p><b>Defined by: </b><a href="class_webdriver_WebDriver.html#getPageSource">webdriver.WebDriver</a></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>&lt;<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">string</a>&gt;</code><dd><p>A promise that will be resolved with the current page source.</p> </dl></div></div></div></div><hr class="fn-sep"><div id="getSession" class="function"><div><h3>getSession()<span class="codelink"><a href="source/lib/webdriver/webdriver.js.src.html#l421">code »</a></span></h3><p><b>Defined by: </b><a href="class_webdriver_WebDriver.html#getSession">webdriver.WebDriver</a></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>&lt;<a href="class_webdriver_Session.html">webdriver.Session</a>&gt;</code><dd><p>A promise for this client&#39;s session.</p> </dl></div></div></div></div><hr class="fn-sep"><div id="getTitle" class="function"><div><h3>getTitle()<span class="codelink"><a href="source/lib/webdriver/webdriver.js.src.html#l814">code »</a></span></h3><p>Schedules a command to retrieve the current page&#39;s title.</p> <p><b>Defined by: </b><a href="class_webdriver_WebDriver.html#getTitle">webdriver.WebDriver</a></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>&lt;<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">string</a>&gt;</code><dd><p>A promise that will be resolved with the current page&#39;s title.</p> </dl></div></div></div></div><hr class="fn-sep"><div id="getWindowHandle" class="function"><div><h3>getWindowHandle()<span class="codelink"><a href="source/lib/webdriver/webdriver.js.src.html#l741">code »</a></span></h3><p>Schedules a command to retrieve they current window handle.</p> <p><b>Defined by: </b><a href="class_webdriver_WebDriver.html#getWindowHandle">webdriver.WebDriver</a></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>&lt;<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">string</a>&gt;</code><dd><p>A promise that will be resolved with the current window handle.</p> </dl></div></div></div></div><hr class="fn-sep"><div id="isElementPresent" class="function"><div><h3>isElementPresent(<wbr>locatorOrElement)<span class="codelink"><a href="source/lib/webdriver/webdriver.js.src.html#l974">code »</a></span></h3><p>Schedules a command to test if an element is present on the page.</p> <p>If given a DOM element, this function will check if it belongs to the document the driver is currently focused on. Otherwise, the function will test if at least one element can be found with the given search criteria.</p> <p><b>Defined by: </b><a href="class_webdriver_WebDriver.html#isElementPresent">webdriver.WebDriver</a></p><div><div class="fn-details"><div><b>Parameters</b></div><dl><dt>locatorOrElement<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 to use, or the actual DOM element to be located by the server.</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>&lt;<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean">boolean</a>&gt;</code><dd><p>A promise that will resolve with whether the element is present on the page.</p> </dl></div></div></div></div><hr class="fn-sep"><div id="launchApp" class="function"><div><h3>launchApp(<wbr>id)<span class="codelink"><a href="source/chrome.js.src.html#l834">code »</a></span></h3><p>Schedules a command to launch Chrome App with given ID.</p> <div><div class="fn-details"><div><b>Parameters</b></div><dl><dt>id<code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">string</a></code><dd><p>ID of the App to launch.</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></code><dd><p>A promise that will be resolved when app is launched.</p> </dl></div></div></div></div><hr class="fn-sep"><div id="manage" class="function"><div><h3>manage()<span class="codelink"><a href="source/lib/webdriver/webdriver.js.src.html#l1056">code »</a></span></h3><p><b>Defined by: </b><a href="class_webdriver_WebDriver.html#manage">webdriver.WebDriver</a></p><div><div class="fn-details"><div><b>Returns</b></div><dl><dt><code><a href="class_webdriver_WebDriver_Options.html">webdriver.WebDriver.Options</a></code><dd><p>The options interface for this instance.</p> </dl></div></div></div></div><hr class="fn-sep"><div id="navigate" class="function"><div><h3>navigate()<span class="codelink"><a href="source/lib/webdriver/webdriver.js.src.html#l1065">code »</a></span></h3><p><b>Defined by: </b><a href="class_webdriver_WebDriver.html#navigate">webdriver.WebDriver</a></p><div><div class="fn-details"><div><b>Returns</b></div><dl><dt><code><a href="class_webdriver_WebDriver_Navigation.html">webdriver.WebDriver.Navigation</a></code><dd><p>The navigation interface for this instance.</p> </dl></div></div></div></div><hr class="fn-sep"><div id="quit" class="function"><div><h3>quit()<span class="codelink"><a href="source/lib/webdriver/webdriver.js.src.html#l444">code »</a></span></h3><p>Schedules a command to quit the current session. After calling quit, this instance will be invalidated and may no longer be used to issue commands against the browser.</p> <p><b>Defined by: </b><a href="class_webdriver_WebDriver.html#quit">webdriver.WebDriver</a></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>&lt;<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Undefined">undefined</a>&gt;</code><dd><p>A promise that will be resolved when the command has completed.</p> </dl></div></div></div></div><hr class="fn-sep"><div id="schedule" class="function"><div><h3><code>&lt;T&gt;</code> schedule(<wbr>command, description)<span class="codelink"><a href="source/lib/webdriver/webdriver.js.src.html#l338">code »</a></span></h3><p>Schedules a <code>webdriver.Command</code> to be executed by this driver&#39;s <code>webdriver.CommandExecutor</code>.</p> <p><b>Defined by: </b><a href="class_webdriver_WebDriver.html#schedule">webdriver.WebDriver</a></p><div><div class="fn-details"><div><b>Parameters</b></div><dl><dt>command<code><a href="class_webdriver_Command.html">webdriver.Command</a></code><dd><p>The command to schedule.</p> <dt>description<code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">string</a></code><dd><p>A description of the command for debugging.</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>&lt;T&gt;</code><dd><p>A promise that will be resolved with the command result.</p> </dl></div></div></div></div><hr class="fn-sep"><div id="setFileDetector" class="function"><div><h3>setFileDetector(<wbr>detector)<span class="codelink"><a href="source/chrome.js.src.html#l824">code »</a></span></h3><p>This function is a no-op as file detectors are not supported by this implementation.</p> <p><b>Overrides: </b><a href="class_webdriver_WebDriver.html#setFileDetector">webdriver.WebDriver</a></p><div><div class="fn-details"><div><b>Parameters</b></div><dl><dt>detector<code><a href="class_webdriver_FileDetector.html">webdriver.FileDetector</a></code><dd><p>The detector to use or <code>null</code>.</p> </dl></div></div></div></div><hr class="fn-sep"><div id="sleep" class="function"><div><h3>sleep(<wbr>ms)<span class="codelink"><a href="source/lib/webdriver/webdriver.js.src.html#l731">code »</a></span></h3><p>Schedules a command to make the driver sleep for the given amount of time.</p> <p><b>Defined by: </b><a href="class_webdriver_WebDriver.html#sleep">webdriver.WebDriver</a></p><div><div class="fn-details"><div><b>Parameters</b></div><dl><dt>ms<code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number">number</a></code><dd><p>The amount of time, in milliseconds, to sleep.</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>&lt;<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Undefined">undefined</a>&gt;</code><dd><p>A promise that will be resolved when the sleep has finished.</p> </dl></div></div></div></div><hr class="fn-sep"><div id="switchTo" class="function"><div><h3>switchTo()<span class="codelink"><a href="source/lib/webdriver/webdriver.js.src.html#l1074">code »</a></span></h3><p><b>Defined by: </b><a href="class_webdriver_WebDriver.html#switchTo">webdriver.WebDriver</a></p><div><div class="fn-details"><div><b>Returns</b></div><dl><dt><code><a href="class_webdriver_WebDriver_TargetLocator.html">webdriver.WebDriver.TargetLocator</a></code><dd><p>The target locator interface for this instance.</p> </dl></div></div></div></div><hr class="fn-sep"><div id="takeScreenshot" class="function"><div><h3>takeScreenshot()<span class="codelink"><a href="source/lib/webdriver/webdriver.js.src.html#l1046">code »</a></span></h3><p>Schedule a command to take a screenshot. The driver makes a best effort to return a screenshot of the following, in order of preference:</p> <ol><li>Entire page </li><li>Current window </li><li>Visible portion of the current frame </li><li>The screenshot of the entire display containing the browser </li></ol> <p><b>Defined by: </b><a href="class_webdriver_WebDriver.html#takeScreenshot">webdriver.WebDriver</a></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>&lt;<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">string</a>&gt;</code><dd><p>A promise that will be resolved to the screenshot as a base-64 encoded PNG.</p> </dl></div></div></div></div><hr class="fn-sep"><div id="touchActions" class="function"><div><h3>touchActions()<span class="codelink"><a href="source/lib/webdriver/webdriver.js.src.html#l486">code »</a></span></h3><p>Creates a new touch sequence using this driver. The sequence will not be scheduled for execution until <a href="class_webdriver_TouchSequence.html#perform"><code>webdriver.TouchSequence#perform</code></a> is called. Example:</p> <pre><code>driver.touchActions(). tap(element1). doubleTap(element2). perform(); </code></pre> <p><b>Defined by: </b><a href="class_webdriver_WebDriver.html#touchActions">webdriver.WebDriver</a></p><div><div class="fn-details"><div><b>Returns</b></div><dl><dt><code><a href="class_webdriver_TouchSequence.html">webdriver.TouchSequence</a></code><dd><p>A new touch sequence for this instance.</p> </dl></div></div></div></div><hr class="fn-sep"><div id="wait" class="function"><div><h3><code>&lt;T&gt;</code> wait(<wbr>condition, opt_timeout, opt_message)<span class="codelink"><a href="source/lib/webdriver/webdriver.js.src.html#l700">code »</a></span></h3><p>Schedules a command to wait for a condition to hold. The condition may be specified by a <a href="class_webdriver_until_Condition.html"><code>webdriver.until.Condition</code></a>, as a custom function, or as a <a href="class_webdriver_promise_Promise.html"><code>webdriver.promise.Promise</code></a>.</p> <p>For a <a href="class_webdriver_until_Condition.html"><code>webdriver.until.Condition</code></a> or function, the wait will repeatedly evaluate the condition until it returns a truthy value. If any errors occur while evaluating the condition, they will be allowed to propagate. In the event a condition returns a <a href="class_webdriver_promise_Promise.html"><code>promise</code></a>, the polling loop will wait for it to be resolved and use the resolved value for whether the condition has been satisified. Note the resolution time for a promise is factored into whether a wait has timed out.</p> <p><em>Example:</em> waiting up to 10 seconds for an element to be present and visible on the page.</p> <pre><code>var button &#61; driver.wait(until.elementLocated(By.id(&#39;foo&#39;)), 10000); button.click(); </code></pre> <p>This function may also be used to block the command flow on the resolution of a <a href="class_webdriver_promise_Promise.html"><code>promise</code></a>. When given a promise, the command will simply wait for its resolution before completing. A timeout may be provided to fail the command if the promise does not resolve before the timeout expires.</p> <p><em>Example:</em> Suppose you have a function, <code>startTestServer</code>, that returns a promise for when a server is ready for requests. You can block a <code>WebDriver</code> client on this promise with:</p> <pre><code>var started &#61; startTestServer(); driver.wait(started, 5 * 1000, &#39;Server should start within 5 seconds&#39;); driver.get(getServerUrl()); </code></pre> <p><b>Defined by: </b><a href="class_webdriver_WebDriver.html#wait">webdriver.WebDriver</a></p><div><div class="fn-details"><div><b>Parameters</b></div><dl><dt>condition<code>(<a href="class_webdriver_promise_Promise.html">webdriver.promise.Promise</a>&lt;T&gt;|<a href="class_webdriver_until_Condition.html">webdriver.until.Condition</a>&lt;T&gt;|function(<a href="class_webdriver_WebDriver.html">webdriver.WebDriver</a>): T)</code><dd><p>The condition to wait on, defined as a promise, condition object, or a function to evaluate as a condition.</p> <dt>opt_timeout<code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number">number</a>=</code><dd><p>How long to wait for the condition to be true.</p> <dt>opt_message<code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">string</a>=</code><dd><p>An optional message to use if the wait times out.</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>&lt;T&gt;</code><dd><p>A promise that will be fulfilled with the first truthy value returned by the condition function, or rejected if the condition times out.</p> </dl></div></div></div></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>