Selenium IDE Commands (Selenese): A Comprehensive Guide to Test Automation
Learn how to use Selenium IDE commands (Selenese) to automate browser actions and create robust test scripts. This tutorial provides a detailed overview of Selenese command categories, syntax, and best practices for efficient web application testing.
Selenium IDE Commands (Selenese)
Selenium IDE commands, also known as Selenese, are used to create automated tests. They allow you to simulate user actions and verify application behavior. Understanding Selenese commands is essential for building effective Selenium test scripts.
Categories of Selenium Commands
Selenese commands are grouped into three main categories:
- Actions: Commands that perform actions on the browser or web page (e.g., opening a URL, clicking an element, typing text). Actions commands affect the state of the application.
- Accessors: Commands that retrieve information from the browser or page (e.g., getting the page title, getting the text of an element). Accessors retrieve information from the application.
- Assertions: Commands that verify that a certain condition is true. Assertions are crucial for verifying the expected results of your test cases.
Actions Commands
Command | Description |
---|---|
open(url) |
Opens the specified URL in the browser. |
type(locator, value) |
Types text into an input field. |
typeKeys(locator, value) |
Simulates typing keys (including special keys like Enter). |
click(locator) |
Clicks a link or button. |
clickAt(locator, coordString) |
Clicks at specific coordinates within an element. |
doubleClick(locator) |
Double-clicks an element. |
focus(locator) |
Sets focus to an element. |
highlight(locator) |
Highlights the element (for debugging purposes). |
close() |
Closes the current browser window. |
store(expression, variableName) |
Stores the result of an expression in a variable. |
waitForCondition(script, timeout) |
Waits for a JavaScript condition to become true. |
Accessors Commands
Command | Description |
---|---|
storeTitle(variableName) |
Stores the page title in a variable. |
storeText(locator, variableName) |
Stores the text of an element in a variable. |
storeValue(locator, variableName) |
Stores the value of an input field in a variable. |
storeTable(tableCellAddress, variableName) |
Stores the text of a table cell in a variable. |
storeLocation(variableName) |
Stores the current URL in a variable. |
storeElementIndex(locator, variableName) |
Stores the index of an element within its parent. |
storeBodyText(variableName) |
Stores the entire page text in a variable. |
storeAllButtons(variableName) |
Stores IDs of all buttons on the page. |
storeAllFields(variableName) |
Stores IDs of all form fields on the page. |
storeAllLinks(variableName) |
Stores URLs of all links on the page. |
Assertions Commands
Command | Description |
---|---|
assertTitle(pattern) |
Verifies the page title. |
assertText(locator, pattern) |
Verifies the text of an element. |
assertValue(locator, pattern) |
Verifies the value of an input field. |
assertSelected(selectLocator, optionLocator) |
Verifies the selected option in a dropdown. |
assertAlert(pattern) |
Verifies an alert's text. |
waitForElementPresent(locator, timeout) |
Waits for an element to appear on the page. |
waitForVisible(locator, timeout) |
Waits for an element to be visible. |