Element Locators tell Selenium which HTML element a command refers to. The format of a locator is:
locatorType=argument
We support the following strategies for locating elements:
- identifier=id
- Select the element with the specified @id attribute. If no match is found, select the first element whose @name attribute is id. (This is normally the default; see below.)
- id=id
- Select the element with the specified @id attribute.
- name=name
- Select the first element with the specified @name attribute.
- username
- name=username
- The name may optionally be followed by one or more element-filters, separated from the name by whitespace. If the filterType is not specified, value is assumed.
- name=flavour value=chocolate
- dom=javascriptExpression
- Find an element using JavaScript traversal of the HTML Document Object Model. DOM locators must begin with "document.".
- dom=document.forms['myForm'].myDropdown
- dom=document.images[56]
- xpath=xpathExpression
- Locate an element using an XPath expression.
- xpath=//img[@alt='The image alt text']
- xpath=//table[@id='table1']//tr[4]/td[2]
- link=textPattern
- Select the link (anchor) element which contains text matching the specified pattern.
- link=The link text
Without an explicit locator prefix, Selenium uses the following default strategies:
Element filters can be used with a locator to refine a list of candidate elements. They are currently used only in the 'name' element-locator.
Filters look much like locators, ie.
filterType=argumentSupported element-filters are:
value=valuePattern
Matches elements based on their values. This is particularly useful for refining a list of similarly-named toggle-buttons.index=index
Selects a single element based on its position in the list (offset from zero).
Various Pattern syntaxes are available for matching string values:
- glob:pattern
- Match a string against a "glob" (aka "wildmat") pattern. "Glob" is a kind of limited regular-expression syntax typically used in command-line shells. In a glob pattern, "*" represents any sequence of characters, and "?" represents any single character. Glob patterns match against the entire string.
- regexp:regexp
- Match a string using a regular-expression. The full power of JavaScript regular-expressions is available.
- exact:string
- Match a string exactly, verbatim, without any of that fancy wildcard stuff.
If no pattern prefix is specified, Selenium assumes that it's a "glob" pattern.
For a list of all members of this type, see DefaultSelenium Members.
System.Object
Selenium.DefaultSelenium
Public static (Shared in Visual Basic) members of this type are safe for multithreaded operations. Instance members are not guaranteed to be thread-safe.
Namespace: Selenium
Assembly: ThoughtWorks.Selenium.Core (in ThoughtWorks.Selenium.Core.dll)