selenium-webdriver
Version:
The official WebDriver JavaScript bindings from the Selenium project
56 lines • 10.7 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>By</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#l42">View Source</a></div><h1>namespace By</h1><dl><dt>Alias for <code><a href="namespace_webdriver_By.html">webdriver.By</a></code></dl><p>A collection of factory functions for creating <a href="class_webdriver_Locator.html"><code>webdriver.Locator</code></a>
instances.</p>
<h2>Functions</h2><div id="className" class="function"><div><h3>className(<wbr>className)<span class="codelink"><a href="source/lib/webdriver/locators.js.src.html#l110">code »</a></span></h3><p>Locates elements that have a specific class name. The returned locator
is equivalent to searching for elements with the CSS selector ".clazz".</p>
<div><div class="fn-details"><div><b>Parameters</b></div><dl><dt>className<code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">string</a></code><dd><p>The class name to search for.</p>
</dl></div><div class="fn-details"><div><b>Returns</b></div><dl><dt><code><a href="class_webdriver_Locator.html">webdriver.Locator</a></code><dd><p>The new locator.</p>
</dl></div></div></div></div><hr class="fn-sep"><div id="css" class="function"><div><h3>css(<wbr>selector)<span class="codelink"><a href="source/lib/webdriver/locators.js.src.html#l123">code »</a></span></h3><p>Locates elements using a CSS selector. For browsers that do not support
CSS selectors, WebDriver implementations may return an
<a href="enum_bot_Error_State.html#INVALID_SELECTOR">invalid selector</a> error. An
implementation may, however, emulate the CSS selector API.</p>
<div><div class="fn-details"><div><b>Parameters</b></div><dl><dt>selector<code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">string</a></code><dd><p>The CSS selector to use.</p>
</dl></div><div class="fn-details"><div><b>Returns</b></div><dl><dt><code><a href="class_webdriver_Locator.html">webdriver.Locator</a></code><dd><p>The new locator.</p>
</dl></div></div></div></div><hr class="fn-sep"><div id="id" class="function"><div><h3>id(<wbr>id)<span class="codelink"><a href="source/lib/webdriver/locators.js.src.html#l132">code »</a></span></h3><p>Locates an element by its 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>The ID to search for.</p>
</dl></div><div class="fn-details"><div><b>Returns</b></div><dl><dt><code><a href="class_webdriver_Locator.html">webdriver.Locator</a></code><dd><p>The new locator.</p>
</dl></div></div></div></div><hr class="fn-sep"><div id="js" class="function"><div><h3>js(<wbr>script, var_args)<span class="codelink"><a href="source/lib/webdriver/locators.js.src.html#l155">code »</a></span></h3><p>Locates an elements by evaluating a
<a href="class_webdriver_WebDriver.html#executeScript">JavaScript expression</a>.
The result of this expression must be an element or list of elements.</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>function(<a href="class_webdriver_WebDriver.html">webdriver.WebDriver</a>): <a href="class_webdriver_promise_Promise.html">webdriver.promise.Promise</a></code><dd><p>A new,
JavaScript-based locator function.</p>
</dl></div></div></div></div><hr class="fn-sep"><div id="linkText" class="function"><div><h3>linkText(<wbr>text)<span class="codelink"><a href="source/lib/webdriver/locators.js.src.html#l142">code »</a></span></h3><p>Locates link elements whose <a href="class_webdriver_WebElement.html#getText">visible
text</a> matches the given string.</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 link text to search for.</p>
</dl></div><div class="fn-details"><div><b>Returns</b></div><dl><dt><code><a href="class_webdriver_Locator.html">webdriver.Locator</a></code><dd><p>The new locator.</p>
</dl></div></div></div></div><hr class="fn-sep"><div id="name" class="function"><div><h3>name(<wbr>name)<span class="codelink"><a href="source/lib/webdriver/locators.js.src.html#l169">code »</a></span></h3><p>Locates elements whose <code>name</code> attribute has the given value.</p>
<div><div class="fn-details"><div><b>Parameters</b></div><dl><dt>name<code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">string</a></code><dd><p>The name attribute to search for.</p>
</dl></div><div class="fn-details"><div><b>Returns</b></div><dl><dt><code><a href="class_webdriver_Locator.html">webdriver.Locator</a></code><dd><p>The new locator.</p>
</dl></div></div></div></div><hr class="fn-sep"><div id="partialLinkText" class="function"><div><h3>partialLinkText(<wbr>text)<span class="codelink"><a href="source/lib/webdriver/locators.js.src.html#l179">code »</a></span></h3><p>Locates link elements whose <a href="class_webdriver_WebElement.html#getText">visible
text</a> contains the given substring.</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 substring to check for in a link's visible text.</p>
</dl></div><div class="fn-details"><div><b>Returns</b></div><dl><dt><code><a href="class_webdriver_Locator.html">webdriver.Locator</a></code><dd><p>The new locator.</p>
</dl></div></div></div></div><hr class="fn-sep"><div id="tagName" class="function"><div><h3>tagName(<wbr>text)<span class="codelink"><a href="source/lib/webdriver/locators.js.src.html#l193">code »</a></span></h3><p>Locates elements with a given tag name. The returned locator is
equivalent to using the
<a href="https://developer.mozilla.org/en-US/docs/Web/API/Element.getElementsByTagName">getElementsByTagName</a>
DOM function.</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 substring to check for in a link's visible text.</p>
</dl></div><div class="fn-details"><div><b>Returns</b></div><dl><dt><code><a href="class_webdriver_Locator.html">webdriver.Locator</a></code><dd><p>The new locator.</p>
</dl></div></div></div></div><hr class="fn-sep"><div id="xpath" class="function"><div><h3>xpath(<wbr>xpath)<span class="codelink"><a href="source/lib/webdriver/locators.js.src.html#l208">code »</a></span></h3><p>Locates elements matching a XPath selector. Care should be taken when
using an XPath selector with a <a href="class_webdriver_WebElement.html"><code>webdriver.WebElement</code></a> as WebDriver
will respect the context in the specified in the selector. For example,
given the selector <code>"//div"</code>, WebDriver will search from the
document root regardless of whether the locator was used with a
WebElement.</p>
<div><div class="fn-details"><div><b>Parameters</b></div><dl><dt>xpath<code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">string</a></code><dd><p>The XPath selector to use.</p>
</dl></div><div class="fn-details"><div><b>Returns</b></div><dl><dt><code><a href="class_webdriver_Locator.html">webdriver.Locator</a></code><dd><p>The new locator.</p>
</dl></div></div></div></div><h2>Type Definitions</h2><div id="By.Hash" class="property"><dl><dt><a href="source/lib/webdriver/locators.js.src.html#l98">By.Hash</a><code>({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>Short-hand expressions for the primary element locator strategies.
For example the following two statements are equivalent:</p>
<pre><code>var e1 = driver.findElement(webdriver.By.id('foo'));
var e2 = driver.findElement({id: 'foo'});
</code></pre>
<p>Care should be taken when using JavaScript minifiers (such as the
Closure compiler), as locator hashes will always be parsed using
the un-obfuscated properties listed.</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>