UNPKG

selenium-webdriver

Version:

The official WebDriver JavaScript bindings from the Selenium project

91 lines (88 loc) 11.2 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>AlertPromise</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>Namespace:</b> <a href="namespace_webdriver.html">webdriver</a></div><div class="codelink"><a href="source/lib/webdriver/webdriver.js.src.html#l2364">View Source</a></div><h1>class AlertPromise</h1><div class="tags"><span>final</span></div><pre class="inheritance"><a href="class_webdriver_Alert.html">webdriver.Alert</a> &#x2514; webdriver.AlertPromise</pre><dl><dt>All implemented interfaces<dd><code>IThenable&lt;T&gt;</code><dd><code><a href="interface_webdriver_promise_Thenable.html">webdriver.promise.Thenable</a>&lt;<a href="class_webdriver_Alert.html">webdriver.Alert</a>&gt;</code></dl><p>AlertPromise is a promise that will be fulfilled with an Alert. This promise serves as a forward proxy on an Alert, allowing calls to be scheduled directly on this instance before the underlying Alert has been fulfilled. In other words, the following two statements are equivalent:</p> <pre><code>driver.switchTo().alert().dismiss(); driver.switchTo().alert().then(function(alert) { return alert.dismiss(); }); </code></pre> <h3>new AlertPromise(<wbr>driver, alert)</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 driver controlling the browser this alert is attached to.</p> <dt>alert<code><a href="interface_webdriver_promise_Thenable.html">webdriver.promise.Thenable</a>&lt;<a href="class_webdriver_Alert.html">webdriver.Alert</a>&gt;</code><dd><p>A thenable that will be fulfilled with the promised alert.</p> </dl></div></div><h2>Instance Methods</h2><div id="accept" class="function"><div><h3>accept()<span class="codelink"><a href="source/lib/webdriver/webdriver.js.src.html#l2396">code »</a></span></h3><p>Defers action until the alert has been located.</p> <p><b>Overrides: </b><a href="class_webdriver_Alert.html#accept">webdriver.Alert</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="cancel" class="function"><div><h3>cancel(<wbr>opt_reason)<span class="codelink"><a href="source/lib/webdriver/webdriver.js.src.html#l2368">code »</a></span></h3><p>Cancels the computation of this promise&#39;s value, rejecting the promise in the process. This method is a no-op if the promise has already been resolved.</p> <p><b>Specified by: </b><a href="interface_webdriver_promise_Thenable.html#cancel">webdriver.promise.Thenable</a></p><div><div class="fn-details"><div><b>Parameters</b></div><dl><dt>opt_reason<code>?(<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">string</a>|<a href="class_webdriver_promise_CancellationError.html">webdriver.promise.CancellationError</a>)=</code><dd><p>The reason this promise is being cancelled.</p> </dl></div></div></div></div><hr class="fn-sep"><div id="dismiss" class="function"><div><h3>dismiss()<span class="codelink"><a href="source/lib/webdriver/webdriver.js.src.html#l2406">code »</a></span></h3><p>Defers action until the alert has been located.</p> <p><b>Overrides: </b><a href="class_webdriver_Alert.html#dismiss">webdriver.Alert</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="getText" class="function"><div><h3>getText()<span class="codelink"><a href="source/lib/webdriver/webdriver.js.src.html#l2386">code »</a></span></h3><p>Defer returning text until the promised alert has been resolved.</p> <p><b>Overrides: </b><a href="class_webdriver_Alert.html#getText">webdriver.Alert</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 text displayed with this alert.</p> </dl></div></div></div></div><hr class="fn-sep"><div id="isPending" class="function"><div><h3>isPending()<span class="codelink"><a href="source/lib/webdriver/webdriver.js.src.html#l2371">code »</a></span></h3><p><b>Specified by: </b><a href="interface_webdriver_promise_Thenable.html#isPending">webdriver.promise.Thenable</a></p><div><div class="fn-details"><div><b>Returns</b></div><dl><dt><code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean">boolean</a></code><dd><p>Whether this promise&#39;s value is still being computed.</p> </dl></div></div></div></div><hr class="fn-sep"><div id="sendKeys" class="function"><div><h3>sendKeys(<wbr>text)<span class="codelink"><a href="source/lib/webdriver/webdriver.js.src.html#l2416">code »</a></span></h3><p>Defers action until the alert has been located.</p> <p><b>Overrides: </b><a href="class_webdriver_Alert.html#sendKeys">webdriver.Alert</a></p><div><div class="fn-details"><div><b>Parameters</b></div><dl><dt>text<code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">string</a></code><dd><p>The text to set.</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 this command has completed.</p> </dl></div></div></div></div><hr class="fn-sep"><div id="then" class="function"><div><h3>then(<wbr>opt_callback, opt_errback)<span class="codelink"><a href="source/lib/webdriver/webdriver.js.src.html#l2374">code »</a></span></h3><p>Registers listeners for when this instance is resolved.</p> <p><b>Specified by: </b><a href="interface_webdriver_promise_Thenable.html#then">webdriver.promise.Thenable</a>, <a href="#then">IThenable</a></p><div><div class="fn-details"><div><b>Parameters</b></div><dl><dt>opt_callback<code>?function(T): (R|IThenable&lt;R&gt;)=</code><dd><p>The function to call if this promise is successfully resolved. The function should expect a single argument: the promise&#39;s resolved value.</p> <dt>opt_errback<code>?function(*): (R|IThenable&lt;R&gt;)=</code><dd><p>The function to call if this promise is rejected. The function should expect a single argument: the rejection reason.</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 new promise which will be resolved with the result of the invoked callback.</p> </dl></div></div></div></div><hr class="fn-sep"><div id="thenCatch" class="function"><div><h3>thenCatch(<wbr>errback)<span class="codelink"><a href="source/lib/webdriver/webdriver.js.src.html#l2377">code »</a></span></h3><p>Registers a listener for when this promise is rejected. This is synonymous with the <code>catch</code> clause in a synchronous API:</p> <pre><code>// Synchronous API: try { doSynchronousWork(); } catch (ex) { console.error(ex); } // Asynchronous promise API: doAsynchronousWork().thenCatch(function(ex) { console.error(ex); }); </code></pre> <p><b>Specified by: </b><a href="interface_webdriver_promise_Thenable.html#thenCatch">webdriver.promise.Thenable</a></p><div><div class="fn-details"><div><b>Parameters</b></div><dl><dt>errback<code>function(*): (R|IThenable&lt;R&gt;)</code><dd><p>The function to call if this promise is rejected. The function should expect a single argument: the rejection reason.</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 new promise which will be resolved with the result of the invoked callback.</p> </dl></div></div></div></div><hr class="fn-sep"><div id="thenFinally" class="function"><div><h3>thenFinally(<wbr>callback)<span class="codelink"><a href="source/lib/webdriver/webdriver.js.src.html#l2380">code »</a></span></h3><p>Registers a listener to invoke when this promise is resolved, regardless of whether the promise&#39;s value was successfully computed. This function is synonymous with the <code>finally</code> clause in a synchronous API:</p> <pre><code>// Synchronous API: try { doSynchronousWork(); } finally { cleanUp(); } // Asynchronous promise API: doAsynchronousWork().thenFinally(cleanUp); </code></pre> <p><strong>Note:</strong> similar to the <code>finally</code> clause, if the registered callback returns a rejected promise or throws an error, it will silently replace the rejection error (if any) from this promise:</p> <pre><code>try { throw Error(&#39;one&#39;); } finally { throw Error(&#39;two&#39;); // Hides Error: one } promise.rejected(Error(&#39;one&#39;)) .thenFinally(function() { throw Error(&#39;two&#39;); // Hides Error: one }); </code></pre> <p><b>Specified by: </b><a href="interface_webdriver_promise_Thenable.html#thenFinally">webdriver.promise.Thenable</a></p><div><div class="fn-details"><div><b>Parameters</b></div><dl><dt>callback<code>function(): (R|IThenable&lt;R&gt;)</code><dd><p>The function to call when this promise is resolved.</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 fulfilled with the callback result.</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>