namespace By
- Alias for
webdriver.By
A collection of factory functions for creating webdriver.Locator
instances.
Functions
className(className)code »
Locates elements that have a specific class name. The returned locator is equivalent to searching for elements with the CSS selector ".clazz".
- className
string
The class name to search for.
webdriver.Locator
The new locator.
css(selector)code »
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.
- selector
string
The CSS selector to use.
webdriver.Locator
The new locator.
id(id)code »
Locates an element by its ID.
- id
string
The ID to search for.
webdriver.Locator
The new locator.
js(script, var_args)code »
Locates an elements by evaluating a JavaScript expression. The result of this expression must be an element or list of elements.
- script
(string|Function)
The script to execute.
- var_args
...*
The arguments to pass to the script.
function(webdriver.WebDriver): webdriver.promise.Promise
A new, JavaScript-based locator function.
linkText(text)code »
Locates link elements whose visible text matches the given string.
- text
string
The link text to search for.
webdriver.Locator
The new locator.
name(name)code »
Locates elements whose name
attribute has the given value.
- name
string
The name attribute to search for.
webdriver.Locator
The new locator.
partialLinkText(text)code »
Locates link elements whose visible text contains the given substring.
- text
string
The substring to check for in a link's visible text.
webdriver.Locator
The new locator.
tagName(text)code »
Locates elements with a given tag name. The returned locator is equivalent to using the getElementsByTagName DOM function.
- text
string
The substring to check for in a link's visible text.
webdriver.Locator
The new locator.
xpath(xpath)code »
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.
- xpath
string
The XPath selector to use.
webdriver.Locator
The new locator.
Type Definitions
- 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.