By is used to create <[Locator]>'s to find Elements or use in any place which accepts a Locator or <[Locatable]>.

by.attr(tagName, attributeName[, value])

  • tagName TagName to scope selection to

  • attributeName The attribute to search for

  • value (Optional) Optional attribute value to compare

  • returns: <[Locator]>

Finds an element containing a specified attribute value

by.css(selector)

  • selector

  • returns: <[Locator]>

Locates an element using a CSS (jQuery) style selector

by.id(id)

  • id

  • returns: <[Locator]>

Finds an element by ID

by.js(func)

  • func

  • returns: <[Locator]>

Recives a function which runs on the page and returns an element or elements.

by.linkText(text)

  • text

  • returns: <[Locator]>

Locates a link containing the specified text.

by.nameAttr(value)

  • value The name attribute to search for.

  • returns: <[Locator]>

Locates elements whose name attribute has the given value.

by.partialLinkText(text)

  • text

  • returns: <[Locator]>

Locates a link (<a> tag) containing some of the specified text.

Example:

await browser.findElement(By.partialLinkText("Checkout"))

by.partialVisibleText(text)

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

  • returns: <[Locator]>

Locates all elements whose textContent contains the given substring and is not hidden by CSS.

by.visibleText(text)

  • text The string to check for in a elements's visible text.

  • returns: <[Locator]>

Locates all elements whose textContent equals the given substring and is not hidden by CSS.

This selector works in multiple stages, by first finding the element matching the text predicate, and then testing whether it is visible ion the viewport and is not occluded by another element or style property.

by.xpath(path)

  • path XPath selector

  • returns: <[Locator]>

Locates an element using an XPath expression

[Locator]: Locator.md#locator