Summary -

In this topic, we described about the below sections -

Scripts are recorded with Selenium IDE in a special test scripting language called Selenese for Selenium. Selenese comes up with commands for bringing out actions in a web browser and restoring data from the resulting pages.

These Selenese commands are used in Selenium IDE that are used to test web applications.

In Selenese, we can perform the test activities on the existence of UI elements based on their HTML tags, testing for specific content, testing for broken links, testing of input fields, selection list options, submitting forms, and table data among other things. Additionally, Selenium commands support testing of window size, mouse position, alerts, Ajax functionality, windows pop-up, event handling, and many other web-application features.

The tests recorded via the plugin can exported to the programming languages like Java, Ruby, Python, etc.

A command in Selenium describes that “what Selenium has to do”. Selenium selenese commands are classified into three types -

  • Actions
  • Accessors
  • Assertions

Let us discuss about these different types of commands in detail.

Actions

Commands that are used to manipulate the application state. During execution, if the command fails then the current step execution has been stopped. For ex- “Click a link” and “doble click”.

Below are the total list of commands that are relation to Actions part -

Command/Syntax Description
click (locator) Enables clicks on a link, button, checkbox or radio button
clickAt (locator,coordString) Enables clicks on an element with the help of locator and co-ordinates
close() Enables the user clicking the "close" button in the title bar of a popup window or tab
contextMenuAt (locator,coordString) Enables opening the context menu of the specified element from a specified location
doubleClick (locator) Enables double clicks on a webelement based on the specified element.
dragAndDrop (locator,movementsString) Drags an element and then drops it based on specified distance.
dragAndDropToObject (Dragobject,dropobject) Drags an element and drops it on another element.
echo (message) Prints the specified message on console which is used for debugging.
fireEvent (locator,eventName) Enables an event, to trigger the corresponding "onevent" handler
focus (locator) Move the focus to the specified element
highlight (locator) Changes the specified element background Color to yellow that is useful for debugging purposes.
mouseDown (locator) Enables a user pressing the left mouse button on the specified element.
mouseUp (locator) Enables the event that occurs when the user releases the mouse button
mouseUpAt (locator,coordString) Enables the event that occurs when the user releases the mouse button at the specified location.
open (url) Opens an URL in the specified browser and it accepts both relative and absolute URLs.
openWindow (url,windowID) Opens a popup window. After opening the window, user need to activate it using the selectWindow command.
pause (waitTime) Waits for the specified amount of time (in milliseconds)
refresh() Enables the user clicking the "Refresh" button on their browser.
select (selectLocator,optionLocator) Select an option from a drop-down using an option locator.
selectWindow (windowID) Selects a popup window using a window locator; once a popup window has been selected, all focus shifts to that window.
store (expression,variableName) The variable name in which the result is to be stored and expression is the value to store.
type (locator,value) Sets the value of an input field, like user typing action.
typeKeys (locator,value) Enables keystroke events on the specified element, as though tester typed the value key-by-key.
waitForCondition (script,timeout) Executes the specified JavaScript snippet repeatedly until it evaluates to "true".
waitForPageToLoad (timeout) Waits for a new page to load.
waitForPopUp (windowID,timeout) Waits for a popup window to appear and load.
windowFocus() Gives focus to the currently selected window
windowMaximize() Resize currently selected window to take up the entire screen

Accessors

Accessors are used to evaluate the application state and results storing in a variable used in assertions. Ex: “storetable” and “storetext”.

Below are the list of Selenium accessors that are used frequently -

Command/Syntax Description
assertErrorOnNext (message) Pings Selenium to expect an error on the next command execution with an expected message.
storeAllButtons (variableName) Retrieves and stores the IDs of all buttons on the page.
storeAllFields (variableName) Retrieves and stores the IDs of all input fields on the page.
storeAllLinks (variableName) storeAllLinks (variableName)
storeAllWindowIds (variableName) Retrieves and stores the IDs of all windows that the browser knows about in an array
storeAllWindowTitles (variableName) Retrieves and stores the names of all windows that the browser knows about in an array.
storeAllWindowNames (variableName) Retrieves and stores the titles of all windows that the browser knows about in an array.
storeAttribute (attributeLocator, variableName) Retrieves and stores the value of an element attribute. The value of the attribute may differ across browsers.
storeBodyText (variableName) Retrieves and stores the entire text of the page.
storeConfirmation (variableName) Retrieves and stores the message of a JavaScript confirmation dialog generated during the previous action.
storeElementIndex (locator, variableName) Retrieves and stores the relative index of an element to its parent (starting from 0)
storeLocation (variableName) JRetrieves and stores the absolute URL of the current page.
storeSelectedIds (selectLocator,variableName) Retrieves and stores all element IDs for selected options in the specified select or multi-select element.
storeSelectedIndex (selectLocator, variableName) storeSelectedIndex (selectLocator, variableName)
storeSelectedLabel (selectLocator, variableName) Retrieves and stores label (visible text) for selected option in the specified select element.
storeSelectedValue (selectLocator,variableName) JRetrieves and stores value (value attribute) for selected option in the specified select element.
storeSelectOptions (selectLocator,variableName) Retrieves and stores all labels in the specified select drop-down.
storeTable (tableCellAddress, variableName) Retrieves and stores the text from a cell of a table. The cellAddress syntax: tableLocator.row.column, where row and column start at 0.
storeText (locator, variableName) Retrieves and stores the text of an element. This works for any element that contains text.
storeTitle (variableName) Retrieves and stores the title of the current page.
storeValue (locator,variableName) Retrieves and stores the (whitespace-trimmed) value of an input field.
storeChecked (locator, variableName) Retrieves and stores whether a toggle-button (checkbox/radio) is checked.
storeElementPresent (locator, variableName) Retrieves and stores that the specified element is somewhere on the page.
storeTextPresent (pattern, variableName) Retrieves and stores that the specified text pattern appears somewhere on the rendered page shown to the user.
storeVisible (locator, variableName) Determines if the specified element is visible.

Assertions

Assertions enable us to verify the application state and compares against the expected. It is used in 3 modes - “assert”, “verify”, and “waitfor”. For ex: “Verify if an item from the radio buttons selected.

The below are the list of mostly used assertions in Selenium -

Command/Syntax Command/Syntax
waitForErrorOnNext (message) Waits for error; used with the accessor assertErrorOnNext.
verifySelected(selectLocator, optionLocator) verifySelected(selectLocator, optionLocator)
waitForSelected (selectLocator, optionLocator) Waits for getting the option selected; used with the accessor assertSelected.
waitForNotSelected (selectLocator, optionLocator) Waits for not getting the option selected; used with accessor the assertSelected.
verifyAlert (pattern) Verifies the alert text; used the with accessor storeAlert.
waitForAlert (pattern) Waits for the alert; used with the accessor storeAlert.
verifyAllButtons (pattern) Verifies the button; used with the accessor storeAllButtons.
waitForAllButtons (pattern) Waits for the button to load; used with the accessor storeAllButtons.
verifyAllLinks (pattern) Verifies all links; used with the accessor storeAllLinks.
waitForAllLinks (pattern) Waits for all links; used with the accessor storeAllLinks.
verifyAllWindowIds (pattern) Verifies the window id; used with the accessor storeAllWindowIds.
waitForAllWindowIds (pattern) Waits the window id; used with the accessor storeAllWindowIds.
verifyAttribute(attributeLocator, pattern) Verifies an attribute of an element; used with the accessor storeAttribute.
waitForAttribute(attributeLocator, pattern) Waits for an attribute of an element; used with accessor storeAttribute.
verifyBodyText(pattern) Verifies the body text; used with the accessor storeBodyText.
waitForBodyText(pattern) Waits for the body text; used with the accessor storeBodyText.
waitForConfirmation(pattern) Waits for confirmation; used with the accessor storeConfirmationPresent.

Element Locators

Element Locators in Selenium help to identify command referring HTML element. These locators can be identified with the help of Firepath and Firebug of Mozilla.

  • Identifier = id Select the element with the specified “id” attribute and select the first element whose @name attribute is id if there is no match.
  • id= id Select the element with a specified ‘id’ attribute.
  • name =name Select the first element with the specified “name” attribute.
  • dom = javascriptExpression Selenium finds an element by evaluating the specified string that allows us to navigate through the HTML Document Object Model using JavaScript.Users cannot return a value but can evaluate as an expression in the block.
  • xpath = xpathExpression Locate an element using an XPath expression.
  • link = textPattern Select the link element (within anchor tags) that contains text matching the specified pattern.
  • css = cssSelectorSyntax (within anchor tags) Select the element using css selector.