Search This Blog

Wednesday, August 4, 2010

Selenium Commands - Part 7

S

select(selectLocator, optionLocator)
Arguments:
• selectLocator - an element locator identifying a drop-down menu
• optionLocator - an option locator (a label by default)
Select an option from a drop-down using an option locator.
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.
• label=labelPattern: matches options based on their labels, i.e. the visible text. (This is the default.)
o label=regexp:^[Oo]ther
• value=valuePattern: matches options based on their values.
o value=other
• id=id: matches options based on their ids.
o id=option1
• index=index: matches an option based on its index (offset from zero).
o index=2
If no option locator prefix is provided, the default behaviour is to match on label.


selectAndWait(selectLocator, optionLocator)
Generated from select(selectLocator, optionLocator)
Arguments:
• selectLocator - an element locator identifying a drop-down menu
• optionLocator - an option locator (a label by default)
Select an option from a drop-down using an option locator.
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.
• label=labelPattern: matches options based on their labels, i.e. the visible text. (This is the default.)
o label=regexp:^[Oo]ther
• value=valuePattern: matches options based on their values.
o value=other
• id=id: matches options based on their ids.
o id=option1
• index=index: matches an option based on its index (offset from zero).
o index=2
If no option locator prefix is provided, the default behaviour is to match on label.


selectFrame(locator)
Arguments:
• locator - an element locator identifying a frame or iframe
Selects a frame within the current window. (You may invoke this command multiple times to select nested frames.) To select the parent frame, use "relative=parent" as a locator; to select the top frame, use "relative=top".
You may also use a DOM expression to identify the frame you want directly, like this: dom=frames["main"].frames["subframe"]


selectWindow(windowID)
Arguments:
• windowID - the JavaScript window ID of the window to select
Selects a popup window; once a popup window has been selected, all commands go to that window. To select the main window again, use null as the target.
Selenium has several strategies for finding the window object referred to by the "windowID" parameter.
1.) if windowID is null, then it is assumed the user is referring to the original window instantiated by the browser).
2.) if the value of the "windowID" parameter is a JavaScript variable name in the current application window, then it is assumed that this variable contains the return value from a call to the JavaScript window.open() method.
3.) Otherwise, selenium looks in a hash it maintains that maps string names to window objects. Each of these string names matches the second parameter "windowName" past to the JavaScript method window.open(url, windowName, windowFeatures, replaceFlag) (which selenium intercepts).
If you're having trouble figuring out what is the name of a window that you want to manipulate, look at the selenium log messages which identify the names of windows created via window.open (and therefore intercepted by selenium). You will see messages like the following for each window as it is opened:
debug: window.open call intercepted; window ID (which you can use with selectWindow()) is "myNewWindow"
In some cases, Selenium will be unable to intercept a call to window.open (if the call occurs during or before the "onLoad" event, for example). (This is bug SEL-339.) In those cases, you can force Selenium to notice the open window's name by using the Selenium openWindow command, using an empty (blank) url, like this: openWindow("", "myFunnyWindow").


setContext(context, logLevelThreshold)
Arguments:
• context - the message to be sent to the browser
• logLevelThreshold - one of "debug", "info", "warn", "error", sets the threshold for browser-side logging
Writes a message to the status bar and adds a note to the browser-side log.
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.)


setCursorPosition(locator, position)
Arguments:
• locator - an element locator pointing to an input element or textarea
• position - the numerical position of the cursor in the field; position should be 0 to move the position to the beginning of the field. You can also set the cursor to -1 to move it to the end of the field.
Moves the text cursor to the specified position in the given input element or textarea. This method will fail if the specified element isn't an input element or textarea.


setCursorPositionAndWait(locator, position)
Generated from setCursorPosition(locator, position)
Arguments:
• locator - an element locator pointing to an input element or textarea
• position - the numerical position of the cursor in the field; position should be 0 to move the position to the beginning of the field. You can also set the cursor to -1 to move it to the end of the field.
Moves the text cursor to the specified position in the given input element or textarea. This method will fail if the specified element isn't an input element or textarea.


setMouseSpeed(pixels)
Arguments:
• pixels - the number of pixels between "mousemove" events
Configure the number of pixels between "mousemove" events during dragAndDrop commands (default=10).
Setting this value to 0 means that we'll send a "mousemove" event to every single pixel in between the start location and the end location; that can be very slow, and may cause some browsers to force the JavaScript to timeout.
If the mouse speed is greater than the distance between the two dragged objects, we'll just send one "mousemove" at the start location and then one final one at the end location.


setMouseSpeedAndWait(pixels)
Generated from setMouseSpeed(pixels)
Arguments:
• pixels - the number of pixels between "mousemove" events
Configure the number of pixels between "mousemove" events during dragAndDrop commands (default=10).
Setting this value to 0 means that we'll send a "mousemove" event to every single pixel in between the start location and the end location; that can be very slow, and may cause some browsers to force the JavaScript to timeout.
If the mouse speed is greater than the distance between the two dragged objects, we'll just send one "mousemove" at the start location and then one final one at the end location.


setSpeed(value)
Arguments:
• value - the number of milliseconds to pause after operation
Set execution speed (i.e., set the millisecond length of a delay which will follow each selenium operation). By default, there is no such delay, i.e., the delay is 0 milliseconds.


setSpeedAndWait(value)
Generated from setSpeed(value)
Arguments:
• value - the number of milliseconds to pause after operation
Set execution speed (i.e., set the millisecond length of a delay which will follow each selenium operation). By default, there is no such delay, i.e., the delay is 0 milliseconds.


setTimeout(timeout)
Arguments:
• timeout - a timeout in milliseconds, after which the action will return with an error
Specifies the amount of time that Selenium will wait for actions to complete.
Actions that require waiting include "open" and the "waitFor*" actions.
The default timeout is 30 seconds.


shiftKeyDown()
Press the shift key and hold it down until doShiftUp() is called or a new page is loaded.


shiftKeyDownAndWait()
Generated from shiftKeyDown()
Press the shift key and hold it down until doShiftUp() is called or a new page is loaded.


shiftKeyUp()
Release the shift key.


shiftKeyUpAndWait()
Generated from shiftKeyUp()
Release the shift key.


storeAlert(variableName)
Generated from getAlert()
Returns:
The message of the most recent JavaScript alert
Retrieves the message of a JavaScript alert generated during the previous action, or fail if there were no alerts.
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.


storeAlertPresent(variableName)
Generated from isAlertPresent()
Returns:
true if there is an alert
Has an alert occurred?
This function never throws an exception


storeAllButtons(variableName)
Generated from getAllButtons()
Returns:
the IDs of all buttons on the page
Returns the IDs of all buttons on the page.
If a given button has no ID, it will appear as "" in this array.


storeAllFields(variableName)
Generated from getAllFields()
Returns:
the IDs of all field on the page
Returns the IDs of all input fields on the page.
If a given field has no ID, it will appear as "" in this array.


storeAllLinks(variableName)
Generated from getAllLinks()
Returns:
the IDs of all links on the page
Returns the IDs of all links on the page.
If a given link has no ID, it will appear as "" in this array.


storeAllWindowIds(variableName)
Generated from getAllWindowIds()
Returns:
the IDs of all windows that the browser knows about.
Returns the IDs of all windows that the browser knows about.

storeAllWindowNames(variableName)
Generated from getAllWindowNames()
Returns:
the names of all windows that the browser knows about.
Returns the names of all windows that the browser knows about.


storeAllWindowTitles(variableName)
Generated from getAllWindowTitles()
Returns:
the titles of all windows that the browser knows about.
Returns the titles of all windows that the browser knows about.


storeAttribute(attributeLocator, variableName)
Generated from getAttribute(attributeLocator)
Arguments:
• attributeLocator - an element locator followed by an
Returns:
the value of the specified attribute
Gets the value of an element attribute.


storeAttributeFromAllWindows(attributeName, variableName)
Generated from getAttributeFromAllWindows(attributeName)
Arguments:
• attributeName - name of an attribute on the windows
Returns:
the set of values of this attribute from all known windows.
Returns every instance of some attribute from all known windows.


storeBodyText(variableName)
Generated from getBodyText()
Returns:
the entire text of the page
Gets the entire text of the page.


storeChecked(locator, variableName)
Generated from isChecked(locator)
Arguments:
• locator - an element locator pointing to a checkbox or radio button
Returns:
true if the checkbox is checked, false otherwise
Gets whether a toggle-button (checkbox/radio) is checked. Fails if the specified element doesn't exist or isn't a toggle-button.


storeConfirmation(variableName)
Generated from getConfirmation()
Returns:
the message of the most recent JavaScript confirmation dialog
Retrieves the message of a JavaScript confirmation dialog generated during the previous action.
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.


storeConfirmationPresent(variableName)
Generated from isConfirmationPresent()
Returns:
true if there is a pending confirmation
Has confirm() been called?
This function never throws an exception


storeCookie(variableName)
Generated from getCookie()
Returns:
all cookies of the current page under test
Return all cookies of the current page under test.


storeCursorPosition(locator, variableName)
Generated from getCursorPosition(locator)
Arguments:
• locator - an element locator pointing to an input element or textarea
Returns:
the numerical position of the cursor in the field
Retrieves the text cursor position in the given input element or textarea; beware, this may not work perfectly on all browsers.
Specifically, if the cursor/selection has been cleared by JavaScript, this command will tend to return the position of the last location of the cursor, even though the cursor is now gone from the page. This is filed as SEL-243.
This method will fail if the specified element isn't an input element or textarea, or there is no cursor in the element.


storeEditable(locator, variableName)
Generated from isEditable(locator)
Arguments:
• locator - an element locator
Returns:
true if the input element is editable, false otherwise
Determines whether the specified input element is editable, ie hasn't been disabled. This method will fail if the specified element isn't an input element.


storeElementHeight(locator, variableName)
Generated from getElementHeight(locator)
Arguments:
• locator - an element locator pointing to an element
Returns:
height of an element in pixels
Retrieves the height of an element


storeElementIndex(locator, variableName)
Generated from getElementIndex(locator)
Arguments:
• locator - an element locator pointing to an element
Returns:
of relative index of the element to its parent (starting from 0)
Get the relative index of an element to its parent (starting from 0). The comment node and empty text node will be ignored.


storeElementPositionLeft(locator, variableName)
Generated from getElementPositionLeft(locator)
Arguments:
• locator - an element locator pointing to an element OR an element itself
Returns:
of pixels from the edge of the frame.
Retrieves the horizontal position of an element


storeElementPositionTop(locator, variableName)
Generated from getElementPositionTop(locator)
Arguments:
• locator - an element locator pointing to an element OR an element itself
Returns:
of pixels from the edge of the frame.
Retrieves the vertical position of an element


storeElementPresent(locator, variableName)
Generated from isElementPresent(locator)
Arguments:
• locator - an element locator
Returns:
true if the element is present, false otherwise
Verifies that the specified element is somewhere on the page.


storeElementWidth(locator, variableName)
Generated from getElementWidth(locator)
Arguments:
• locator - an element locator pointing to an element
Returns:
width of an element in pixels
Retrieves the width of an element


storeEval(script, variableName)
Generated from getEval(script)
Arguments:
• script - the JavaScript snippet to run
Returns:
the results of evaluating the snippet
Gets the result of evaluating the specified JavaScript snippet. The snippet may have multiple lines, but only the result of the last line will be returned.
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.browserbot.findElement("foo") where "foo" is your locator.


storeEval(script, variableName)
Generated from getEval(script)
Arguments:
• script - the JavaScript snippet to run
Returns:
the results of evaluating the snippet
Gets the result of evaluating the specified JavaScript snippet. The snippet may have multiple lines, but only the result of the last line will be returned.
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.browserbot.findElement("foo") where "foo" is your locator.


storeExpression(expression, variableName)
Generated from getExpression(expression)
Arguments:
• expression - the value to return
Returns:
the value passed in
Returns the specified expression.
This is useful because of JavaScript preprocessing. It is used to generate commands like assertExpression and waitForExpression.


storeHtmlSource(variableName)
Generated from getHtmlSource()
Returns:
the entire HTML source
Returns the entire HTML source between the opening and closing "html" tags.


storeLocation(variableName)
Generated from getLocation()
Returns:
the absolute URL of the current page
Gets the absolute URL of the current page.


storeLogMessages(variableName)
Generated from getLogMessages()
Returns:
all log messages seen since the last call to this API
Return the contents of the log.
This is a placeholder intended to make the code generator make this API available to clients. The selenium server will intercept this call, however, and return its recordkeeping of log messages since the last call to this API. Thus this code in JavaScript will never be called.
The reason I opted for a servercentric solution is to be able to support multiple frames served from different domains, which would break a centralized JavaScript logging mechanism under some conditions.


storeMouseSpeed(variableName)
Generated from getMouseSpeed()
Returns:
the number of pixels between "mousemove" events during dragAndDrop commands (default=10)
Returns the number of pixels between "mousemove" events during dragAndDrop commands (default=10).


storeOrdered(locator1, locator2, variableName)
Generated from isOrdered(locator1, locator2)
Arguments:
• locator1 - an element locator pointing to the first element
• locator2 - an element locator pointing to the second element
Returns:
true if two elements are ordered and have same parent, false otherwise
Check if these two elements have same parent and are ordered. Two same elements will not be considered ordered.


storePrompt(variableName)
Generated from getPrompt()
Returns:
the message of the most recent JavaScript question prompt
Retrieves the message of a JavaScript question prompt dialog generated during the previous action.
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.


storePromptPresent(variableName)
Generated from isPromptPresent()
Returns:
true if there is a pending prompt
Has a prompt occurred?
This function never throws an exception


storeSelectOptions(selectLocator, variableName)
Generated from getSelectOptions(selectLocator)
Arguments:
• selectLocator - an element locator identifying a drop-down menu
Returns:
an array of all option labels in the specified select drop-down
Gets all option labels in the specified select drop-down.


storeSelectedId(selectLocator, variableName)
Generated from getSelectedId(selectLocator)
Arguments:
• selectLocator - an element locator identifying a drop-down menu
Returns:
the selected option ID in the specified select drop-down
Gets option element ID for selected option in the specified select element.


storeSelectedIds(selectLocator, variableName)
Generated from getSelectedIds(selectLocator)
Arguments:
• selectLocator - an element locator identifying a drop-down menu
Returns:
an array of all selected option IDs in the specified select drop-down
Gets all option element IDs for selected options in the specified select or multi-select element.


storeSelectedIndex(selectLocator, variableName)
Generated from getSelectedIndex(selectLocator)
Arguments:
• selectLocator - an element locator identifying a drop-down menu
Returns:
the selected option index in the specified select drop-down
Gets option index (option number, starting at 0) for selected option in the specified select element.


storeSelectedIndexes(selectLocator, variableName)
Generated from getSelectedIndexes(selectLocator)
Arguments:
• selectLocator - an element locator identifying a drop-down menu
Returns:
an array of all selected option indexes in the specified select drop-down
Gets all option indexes (option number, starting at 0) for selected options in the specified select or multi-select element.


storeSelectedLabel(selectLocator, variableName)
Generated from getSelectedLabel(selectLocator)
Arguments:
• selectLocator - an element locator identifying a drop-down menu
Returns:
the selected option label in the specified select drop-down
Gets option label (visible text) for selected option in the specified select element.


storeSelectedLabels(selectLocator, variableName)
Generated from getSelectedLabels(selectLocator)
Arguments:
• selectLocator - an element locator identifying a drop-down menu
Returns:
an array of all selected option labels in the specified select drop-down
Gets all option labels (visible text) for selected options in the specified select or multi-select element.


storeSelectedValue(selectLocator, variableName)
Generated from getSelectedValue(selectLocator)
Arguments:
• selectLocator - an element locator identifying a drop-down menu
Returns:
the selected option value in the specified select drop-down
Gets option value (value attribute) for selected option in the specified select element.


storeSelectedValues(selectLocator, variableName)
Generated from getSelectedValues(selectLocator)
Arguments:
• selectLocator - an element locator identifying a drop-down menu
Returns:
an array of all selected option values in the specified select drop-down
Gets all option values (value attributes) for selected options in the specified select or multi-select element.


storeTable(tableCellAddress, variableName)
Generated from getTable(tableCellAddress)
Arguments:
• tableCellAddress - a cell address, e.g. "foo.1.4"
Returns:
the text from the specified cell
Gets the text from a cell of a table. The cellAddress syntax tableLocator.row.column, where row and column start at 0.


storeText(locator, variableName)
Generated from getText(locator)
Arguments:
• locator - an element locator
Returns:
the text of the element
Gets the text of an element. This works for any element that contains text. This command uses either the textContent (Mozilla-like browsers) or the innerText (IE-like browsers) of the element, which is the rendered text shown to the user.



storeTextPresent(pattern, variableName)
Generated from isTextPresent(pattern)
Arguments:
• pattern - a pattern to match with the text of the page
Returns:
true if the pattern matches the text, false otherwise
Verifies that the specified text pattern appears somewhere on the rendered page shown to the user.


storeTitle(variableName)
Generated from getTitle()
Returns:
the title of the current page
Gets the title of the current page.


storeValue(locator, variableName)
Generated from getValue(locator)
Arguments:
• locator - an element locator
Returns:
the element value, or "on/off" for checkbox/radio elements
Gets the (whitespace-trimmed) value of an input field (or anything else with a value parameter). For checkbox/radio elements, the value will be "on" or "off" depending on whether the element is checked or not.


storeVisible(locator, variableName)
Generated from isVisible(locator)
Arguments:
• locator - an element locator
Returns:
true if the specified element is visible, false otherwise
Determines if the specified element is visible. An element can be rendered invisible by setting the CSS "visibility" property to "hidden", or the "display" property to "none", either for the element itself or one if its ancestors. This method will fail if the element is not present.


storeWhetherThisFrameMatchFrameExpression(currentFrameString, target, variableName)
Generated from getWhetherThisFrameMatchFrameExpression(currentFrameString, target)
Arguments:
• currentFrameString - starting frame
• target - new frame (which might be relative to the current one)
Returns:
true if the new frame is this code's window
Determine whether current/locator identify the frame containing this running code.
This is useful in proxy injection mode, where this code runs in every browser frame and window, and sometimes the selenium server needs to identify the "current" frame. In this case, when the test calls selectFrame, this routine is called for each frame to figure out which one has been selected. The selected frame will return true, while all others will return false.


storeWhetherThisWindowMatchWindowExpression(currentWindowString, target, variableName)
Generated from getWhetherThisWindowMatchWindowExpression(currentWindowString, target)
Arguments:
• currentWindowString - starting window
• target - new window (which might be relative to the current one, e.g., "_parent")
Returns:
true if the new window is this code's window
Determine whether currentWindowString plus target identify the window containing this running code.
This is useful in proxy injection mode, where this code runs in every browser frame and window, and sometimes the selenium server needs to identify the "current" window. In this case, when the test calls selectWindow, this routine is called for each window to figure out which one has been selected. The selected window will return true, while all others will return false.


submit(formLocator)
Arguments:
• formLocator - an element locator for the form you want to submit
Submit the specified form. This is particularly useful for forms without submit buttons, e.g. single-input "Search" forms.


submitAndWait(formLocator)
Generated from submit(formLocator)
Arguments:
• formLocator - an element locator for the form you want to submit
Submit the specified form. This is particularly useful for forms without submit buttons, e.g. single-input "Search" forms.