# Namespace webdriver.By

code »

A collection of factory functions for creating `webdriver.Locator` instances.

Show:Public Protected Private

## Type Definitions

code »webdriver.By.Hash : `({className: string}|{css: string}|{id: string}|{js: string}|{linkText: string}|{name: string}|{partialLinkText: string}|{tagName: string}|{xpath: string})`
Short-hand expressions for the primary element locator strategies. For example the following two statements are equivalent: `

     var e1 = driver.findElement(webdriver.By.id('foo'));
     var e2 = driver.findElement({id: 'foo'});

`

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 below.

## Global Functions

code »webdriver.By.className ( className ) ⇒ `!webdriver.Locator`

Locates elements that have a specific class name. The returned locator is equivalent to searching for elements with the CSS selector ".clazz".

Parameters

className: `string`
  The class name to search for.

Returns

The new locator.

code »webdriver.By.css ( selector ) ⇒ `!webdriver.Locator`

Locates elements using a CSS selector. For browsers that do not support CSS selectors, WebDriver implementations may return an `invalid selector` error. An implementation may, however, emulate the CSS selector API.

Parameters

selector: `string`
  The CSS selector to use.

Returns

The new locator.

code »webdriver.By.id ( id ) ⇒ `!webdriver.Locator`

Locates an element by its ID.

Parameters

id: `string`
  The ID to search for.

Returns

The new locator.

code »webdriver.By.js ( script, var_args ) ⇒ `function(!webdriver.WebDriver): !webdriver.promise.Promise`

Locates an elements by evaluating a `JavaScript expression`. The result of this expression must be an element or list of elements.

Parameters

script: `!(string|Function)`
  The script to execute.
var_args: `...*`
  The arguments to pass to the script.

Returns

A new, JavaScript-based locator function.

code »webdriver.By.linkText ( text ) ⇒ `!webdriver.Locator`

Locates link elements whose `visible text` matches the given string.

Parameters

text: `string`
  The link text to search for.

Returns

The new locator.

code »webdriver.By.name ( name ) ⇒ `!webdriver.Locator`

Locates elements whose `name` attribute has the given value.

Parameters

name: `string`
  The name attribute to search for.

Returns

The new locator.

code »webdriver.By.partialLinkText ( text ) ⇒ `!webdriver.Locator`

Locates link elements whose `visible text` contains the given substring.

Parameters

text: `string`
  The substring to check for in a link's visible text.

Returns

The new locator.

code »webdriver.By.tagName ( text ) ⇒ `!webdriver.Locator`

Locates elements with a given tag name. The returned locator is equivalent to using the `getElementsByTagName` DOM function.

Parameters

text: `string`
  The substring to check for in a link's visible text.

Returns

The new locator.

code »webdriver.By.xpath ( xpath ) ⇒ `!webdriver.Locator`

Locates elements matching a XPath selector. Care should be taken when using an XPath selector with a `webdriver.WebElement` as WebDriver will respect the context in the specified in the selector. For example, given the selector `"//div"`, WebDriver will search from the document root regardless of whether the locator was used with a WebElement.

Parameters

xpath: `string`
  The XPath selector to use.

Returns

The new locator.