By

Describes a mechanism for locating an element on the page.

Constructor

new By(using, value)

Parameters:
NameTypeDescription
usingstring

the name of the location strategy to use.

valuestring

the value to search for.

Members

using :string

Type:
  • string

value :string

Type:
  • string

Methods

toString()

(static) className(name) → (non-null) {By}

Locates elements that have a specific class name.

Parameters:
NameTypeDescription
namestring

The class name to search for.

Returns:

The new locator.

Type: 
By

(static) css(selector) → (non-null) {By}

Locates elements using a CSS selector.

Parameters:
NameTypeDescription
selectorstring

The CSS selector to use.

Returns:

The new locator.

Type: 
By

(static) id(id) → (non-null) {By}

Locates elements by the ID attribute. This locator uses the CSS selector *[id="$ID"], not document.getElementById.

Parameters:
NameTypeDescription
idstring

The ID to search for.

Returns:

The new locator.

Type: 
By

(static) js(scriptnon-null, …var_args)

Locates elements by evaluating a script that defines the body of a JavaScript function. The return value of this function must be an element or an array-like list of elements. When this locator returns a list of elements, but only one is expected, the first element in this list will be used as the single element value.

Parameters:
NameTypeAttributesDescription
scriptstring | function

The script to execute.

var_args*<repeatable>

The arguments to pass to the script.

Returns:

(static) linkText(text) → (non-null) {By}

Locates link elements whose visible text matches the given string.

Parameters:
NameTypeDescription
textstring

The link text to search for.

Returns:

The new locator.

Type: 
By

(static) name(name) → (non-null) {By}

Locates elements whose name attribute has the given value.

Parameters:
NameTypeDescription
namestring

The name attribute to search for.

Returns:

The new locator.

Type: 
By

(static) partialLinkText(text) → (non-null) {By}

Locates link elements whose visible text contains the given substring.

Parameters:
NameTypeDescription
textstring

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

Returns:

The new locator.

Type: 
By

(static) tagName(name) → (non-null) {By}

Locates elements with a given tag name.

Parameters:
NameTypeDescription
namestring

The tag name to search for.

Returns:

The new locator.

Type: 
By

(static) xpath(xpath) → (non-null) {By}

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:
NameTypeDescription
xpathstring

The XPath selector to use.

Returns:

The new locator.

Type: 
By