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.
Can also be used to set the value of combo boxes, check boxes, etc. In these cases, value should be the value of the option selected, not the visible text.
Option locators provide different ways of specifying options of an HTML Select element (e.g. for selecting a specific option, or for asserting that the selected option satisfies a specification). There are several forms of Select Option Locator.
If no option locator prefix is provided, the default behaviour is to match on label.
This function never throws an exception
This function never throws an exception
This function never throws an exception
Getting an alert has the same effect as manually clicking OK. If an alert is generated but you do not get/verify it, the next Selenium action will fail.
NOTE: under Selenium, JavaScript alerts will NOT pop up a visible alert dialog.
NOTE: Selenium does NOT support JavaScript alerts that are generated in a page's onload() event handler. In this case a visible dialog WILL be generated and Selenium will hang until someone manually clicks OK.
By default, the confirm function will return true, having the same effect as manually clicking OK. This can be changed by prior execution of the chooseCancelOnNextConfirmation command. If an confirmation is generated but you do not get/verify it, the next Selenium action will fail.
NOTE: under Selenium, JavaScript confirmations will NOT pop up a visible dialog.
NOTE: Selenium does NOT support JavaScript confirmations that are generated in a page's onload() event handler. In this case a visible dialog WILL be generated and Selenium will hang until you manually click OK.
Successful handling of the prompt requires prior execution of the answerOnNextPrompt command. If a prompt is generated but you do not get/verify it, the next Selenium action will fail.
NOTE: under Selenium, JavaScript prompts will NOT pop up a visible dialog.
NOTE: Selenium does NOT support JavaScript prompts that are generated in a page's onload() event handler. In this case a visible dialog WILL be generated and Selenium will hang until someone manually clicks OK.
Note that, by default, the snippet will run in the context of the "selenium"
object itself, so this
will refer to the Selenium object, and window
will
refer to the top-level runner test window, not the window of your application.
If you need a reference to the window of your application, you can refer
to this.browserbot.getCurrentWindow()
and if you need to use
a locator to refer to a single element in your application page, you can
use this.page().findElement("foo")
where "foo" is your locator.
See the select command for more information about option locators.
If a given button has no ID, it will appear as "" in this array.
If a given link has no ID, it will appear as "" in this array.
If a given field has no ID, it will appear as "" in this array.
If logLevelThreshold is specified, set the threshold for logging to that level (debug, info, warn, error).
(Note that the browser-side logs will not be sent back to the server, and are invisible to the Client Driver.)
This is useful because of JavaScript preprocessing. It is used to generate commands like assertExpression and storeExpression.
Note that, by default, the snippet will be run in the runner's test window, not in the window
of your application. To get the window of your application, you can use
the JavaScript snippet selenium.browserbot.getCurrentWindow()
, and then
run your JavaScript in there
Actions that require waiting include "open" and the "waitFor*" actions.
The default timeout is 30 seconds.You can use this command instead of the "AndWait" suffixes, "clickAndWait", "selectAndWait", "typeAndWait" etc. (which are only available in the JS API).
Selenium constantly keeps track of new pages loading, and sets a "newPageLoaded" flag when it first notices a page load. Running any other Selenium command after turns the flag to false. Hence, if you want to wait for a page to load, you must wait immediately after a Selenium command that caused a page-load.