Skip to main content

Frequently Used Selenium Commands

The following commands are available to create scripts which can be run by our service.

These are mainly Selenium commands but also include some custom commands for our service. The commands have either 0, 1 or 2 arguments, as indicated in the table.

Name
Description
Arg1
Arg2
Open
Open a URL.
url – the URL to open; may be relative or absolute
Assert Title
Check the title of a web page.
the title to check
Click and Wait
Click on a link and wait for the page to load
locator – an element locator
Click
Click on a link in the page.
locator – an element locator
Type
Type content into a entry box on the web page.
locator – an element locator
value – the value to type
Wait
Wait for a number of seconds
time – time to wait in seconds
Capture Screenshot
Capture a screenshot of the current page.
Add Selection
Add a selection to the set of selected options in a multi-select element using an option locator.
locator – an element locator identifying a multi-select box
optionLocator – an option locator (a label by default)
Alt Key Down
Press the alt key and hold it down until ALTKEYUP is called or a new page is loaded.
Alt Key Up
Release the alt key.
Answer on Next Prompt
Return the specified answer string in response to the next JavaScript prompt.
answer – the answer to give in response to the prompt pop-up
Check
Check a toggle-button (checkbox/radio).
locator – an element locator
Click At
Clicks on a link, button, checkbox or radio button.
locator – an element locator
coordString – specifies the x,y position (i.e. – 10,20) of the mouse event relative to the element returned by the locator.
Close
Simulates the user clicking the “close” button in the titlebar of a popup window or tab.
Control Key Down
Press the control key and hold it down until doControlUp() is called or a new page is loaded.
Control Key Up
Release the control key.
Double Click
Double clicks on a link, button, checkbox or radio button.
locator – an element locator
Double Click At
Doubleclicks on a link, button, checkbox or radio button.
locator – an element locator
coordString – specifies the x,y position (i.e. – 10,20) of the mouse event relative to the element returned by the locator.
Drag and Drop
Drags an element a certain distance and then drops it.
locator – an element locator
movementsString – offset in pixels from the current location to which the element should be moved, e.g., “+70,-300″
Drag and Drop to Object
Drags an element and drops it on another element.
locatorOfObjectToBeDragged – an element to be dragged
locatorOfDragDestinationObject – an element whose location (i.e., whose center-most pixel) will be the point where locatorOfObjectToBeDragged is dropped
Fire Event
Explicitly simulate an event, to trigger the corresponding “onevent” handler.
locator – an element locator
eventName – the event name, e.g. “focus” or “blur”
Get Alert
Retrieves the message of a JavaScript alert generated during the previous action, or fail if there were no alerts.
Get Confirmation
Retrieves the message of a JavaScript confirmation dialog generated during the previous action.
Get Prompt
Retrieves the message of a JavaScript question prompt dialog generated during the previous action.
Go Back
Simulates the user clicking the “back” button on their browser.
Is Text Present
Verifies that the specified text pattern appears somewhere on the rendered page shown to the user.
the text that should appear on the page
Key Down
Simulates a user pressing a key (without releasing it yet).
locator – an element locator
keySequence – Either be a string(“\” followed by the numeric keycode of the key to be pressed, normally the ASCII value of that key), or a single character. For example: “w”, “\119″.
Key Press
Simulates a user pressing and releasing a key.
locator – an element locator
keySequence – Either be a string(“\” followed by the numeric keycode of the key to be pressed, normally the ASCII value of that key), or a single character. For example: “w”, “\119″.
Key Up
Simulates a user releasing a key.
locator – an element locator
keySequence – Either be a string(“\” followed by the numeric keycode of the key to be pressed, normally the ASCII value of that key), or a single character. For example: “w”, “\119″.
Mouse Down
Simulates a user pressing the mouse button (without releasing it yet) on the specified element.
locator – an element locator
Mouse Down At
Simulates a user pressing the mouse button (without releasing it yet) at the specified location.
locator – an element locator
coordString – specifies the x,y position (i.e. – 10,20) of the mouse event relative to the element returned by the locator.
Mouse Move
Simulates a user pressing and moving the mouse button (without releasing it yet) on the specified element.
locator – an element locator
Mouse Move At
Simulates a user pressing and moving the mouse button (without releasing it yet) on the specified element.
locator – an element locator
coordString – specifies the x,y position (i.e. – 10,20) of the mouse event relative to the element returned by the locator.
Mouse Out
Simulates a user moving the mouse pointer away from the specified element.
locator – an element locator
Mouse Over
Simulates a user hovering a mouse over the specified element.
locator – an element locator
Mouse Up
Simulates the event that occurs when the user releases the mouse button (i.e., stops holding the button down) on the specified element.
locator – an element locator
Mouse Up At
Simulates the event that occurs when the user releases the mouse button (i.e., stops holding the button down) at the specified location.
locator – an element locator
coordString – specifies the x,y position (i.e. – 10,20) of the mouse event relative to the element returned by the locator.
Open Window
Opens a popup window (if a window with that ID isn’t already open).
url – the URL to open, which can be blank
windowID – the JavaScript window ID of the window to select
Refresh
Simulates the user clicking the “Refresh” button on their browser.
Remove All Selections
Unselects all of the selected options in a multi-select element.
locator – an element locator identifying a multi-select box
Remove Selection
Remove a selection from the set of selected options in a multi-select element using an option locator.
locator – an element locator identifying a multi-select box
optionLocator – an option locator (a label by default)
Select
Select an option from a drop-down using an option locator.
locator – an element locator identifying a multi-select box
optionLocator – an option locator (a label by default)
Shift Key Down
Press the shift key and hold it down until SHIFTKEYUP is called or a new page is loaded.
Shift Key Up
Release the shift key.
Submit
Submit the specified form.
formLocator – an element locator for the form you want to submit
Type Keys
Simulates keystroke events on the specified element, as though you typed the value key-by-key.
locator – an element locator
value – the value to type
Uncheck
Uncheck a toggle-button (checkbox/radio)
locator – an element locator
Append
Append content to a entry box on the web page. The new content is added to the end of the existing content.
locator – an element locator
value – the content to append
Dummy
A dummy command that does not do anything.
Unsupported
Commands that are not recognised when a script is uploaded, are mapped to this.
Select Frame
Selects a frame within the current window.
locator – an element locator identifying a frame or iframe
Select Window
Selects a popup window; once a popup window has been selected, all commands go to that window.
windowID – the JavaScript window ID of the window to select
Window Focus
Gives focus to the currently selected window
Store Alert
Stores the message of the most recent JavaScript alert.
Cancel On Next
Simulate the user clicking Cancel to the next Confirmation.
OK On Next
Undo the effect of calling ‘Cancel On Next’.
Create Cookie
Create a new cookie whose path and domain are same with those of current page under test, unless you specified a path for this cookie explicitly.
nameValuePair – name and value of the cookie in a format “name=value”
optionsString – options for the cookie. Currently supported options include ‘path’ and ‘max_age’. the optionsString’s format is “path=/path/, max_age=60″. The order of options are irrelevant, the unit of the value of ‘max_age’ is second.
Delete Cookie
Delete a named cookie with specified path.
name – the name of the cookie to be deleted.
path – the path property of the cookie to be deleted.
Meta Key Down
Press the meta key and hold it down until ‘Meta Key Up’ command is called or a new page is loaded.
Meta Key Up
Release the meta key.
Pause
Wait for the specified amount of time (in milliseconds).
waitTime – the amount of time to sleep (in milliseconds).
Set Cursor Position
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.
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.
Set Mouse Speed
Configure the number of pixels between “mousemove” events during dragAndDrop commands (default=10).
pixels – the number of pixels between “mousemove” events.
Set Speed
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.
value – the number of milliseconds to pause after operation.
Wait For Frame To Load
Waits for a new frame to load.
frameAddress – FrameAddress from the server side.
timeout – a timeout in milliseconds, after which this command will return with an error.
Wait For Page To Load
Waits for a new page to load.
timeout – a timeout in milliseconds, after which this command will return with an error.
Wait For PopUp
Waits for a popup window to appear and load up.
windowID – the JavaScript window ID of the window that will appear.
timeout – a timeout in milliseconds, after which the action will return with an error.
Assert Text Present
Asserts if the specified text IS NOT present on the page.
the text that should appear on the page
Assert Text Not Present
Asserts if the specified text IS present on the page.
the text that should NOT appear on the page
Verify Text Present
Verifies that the specified text IS present – if it is not, it is an error.
the text that should appear on the page
Verify Text Not Present
Verifies that the specified text IS NOT present – if it is, it is an error.
the text that should NOT appear on the page
Assert Pattern
Asserts that a pattern IS present within the page source.
the pattern that should appear within the page source
Assert No Pattern
Asserts that a pattern IS NOT present within the page source.
the pattern that should NOT appear within the page source
Cloud Testing Internal Command
Internal Cloud Testing Command – DO NOT USE
n/a
n/a
Assert Value
Asserts that the value of the specified input field matches the pattern specified.
locator – an element locator pointing to an input element
the text or pattern that should appear in the input field
Assert Not Value
Asserts that the value of the specified input field DOES NOT match the pattern specified.
locator – an element locator pointing to an input element
the text or pattern that should NOT appear in the input field
Verify Value
Verifies that the value of the specified input field matches the pattern specified.
locator – an element locator pointing to an input element
the text or pattern that should appear in the input field
Verify Not Value
Verifies that the value of the specified input field DOES NOT match the pattern specified.
locator – an element locator pointing to an input element
the text or pattern that should NOT appear in the input field
Assert Checked
Asserts that the toggle-button is checked.
locator – an element locator pointing to a toggle-button.
Assert Not Checked
Asserts that the toggle-button is NOT checked.
locator – an element locator pointing to a toggle-button.
Verify Checked
Verifies that the toggle-button is checked.
locator – an element locator pointing to a toggle-button.
Verify Not Checked
Verifies that the toggle-button is NOT checked.
locator – an element locator pointing to a toggle-button.
Assert Tex
Asserts that the text is present at the specific locator.
locator – an element locator pointing to an element that contains text.
the text or pattern that should appear
Assert Not Text
Asserts that the text is NOT present at the specific locator.
locator – an element locator pointing to an element that contains text.
the text or pattern that should NOT appear
Verify Text
Verifies that the text is present at the specific locator.
locator – an element locator pointing to an element that contains text.
the text or pattern that should appear
Verify Not Text
Verifies that the text is NOT present at the specific locator.
locator – an element locator pointing to an element that contains text.
the text or pattern that should NOT appear
Assert Alert
Asserts that the value of the alert matches the pattern specified.
the pattern that should appear as the alert
Assert Alert Not Present
Asserts if an alert is not present
Assert Alert Present
Asserts if an alert is present
Store Alert Present
Returns if an alert was present or not.
a dummy variable – the value is NOT stored into it
Verify Alert
Verifies that the value of the alert matches the pattern specified.
the pattern that should appear as the alert
Verify Alert Not Present
Verifies that an alert IS NOT present.
Verify Alert Present
Verifies that an alert IS present.
Wait For Alert
Waits for the alert matching the pattern to appear.
the pattern that should appear as the alert
Wait For Alert Not Present
Waits for an alert not present
Wait For Alert Present
Waits for an alert to be present
Assert Confirmation
Asserts that the value of the confirmation matches the pattern specified.
the pattern that should appear as the confirmation.
Assert Confirmation Not Present
Asserts if a confirmation is NOT present.
Assert Confirmation Present
Asserts if a confirmation is present.
Store Confirmation
Stores the message from the most recent confirmation.
Store Confirmation Present
Returns if an confirmation was present or not.
a dummy variable – the value is NOT stored into it
Verify Confirmation
Verifies that the value of the confirmation matches the pattern specified.
the pattern that should appear as the confirmation.
Verify Confirmation Not Present
Verifies if a confirmation is NOT present.
Verify Confirmation Present
Verifies if a confirmation is present.
Wait For Confirmation
Waits for the confirmation matching the pattern to appear.
the pattern that should appear as the confirmation.
Wait For Confirmation Not Present
Waits for a confirmation not to be present.
Wait For Confirmation Present
Waits for a confirmation to be present.

Comments

Popular posts from this blog

SSO with SAML login scenario in JMeter

SAML(Security Assertion Markup Language) is increasingly being used to perform single sign-on(SSO) operations. As WikiPedia puts it, SAML is an XML-based open standard data format for exchanging authentication and authorization data between parties, in particular, between an identity provider and a service provider. With the rise in use of SAML in web applications, we may need to handle this in JMeter. This step-by-step tutorial shows SAML JMeter scenario to perform login operation. First request from JMeter is a GET request to fetch Login page. We need to fetch two values ‘SAMLRequest’ and ‘RelayState’ from the Login page response data. We can do this by using  Regular Expression Extractor . These two values need to be sent in POST request to service provider. Refer below image to see how to do this. We will get an HTML login page as a response to the request sent in 1st step. We need to fetch values of some hidden elements to pass it in the next request. We can do this b

JMeter Exceeded Maximum Number of Redirects Error Solution

While running performance test, JMeter allows maximum 5 redirects by default. However, if your system demands more than 5 redirects, it may result in JMeter exceeded maximum number of redirects error. In this post, we have listed down steps to overcome this error. Actual error in JMeter: Response code: “Non HTTP response code: java.io.IOException” Response message: “Non HTTP response message: Exceeded maximum number of redirects: 5” This error is noticed because  JMeter  allows maximum 5 redirects by default and your system may be using more than 5 redirects. You need to increase this count to more than 5 in jmeter.properties file. Follow below steps to achieve this. Navigate to /bin directory of your JMeter installation. Locate jmeter.properties file and open it in any editor. Search for “httpsampler.max_redirects” property in opened file. Uncomment the above property by removing # before it. Change to value to more than 5 Eg. 20. Save the file and restart JMeter. If

VBScript Code - Function to convert CSV file into excel and viceversa in QTP using VBScript

We at times are required to convert excel files into csv to read as flat files and sometime require to convert a csv file into excel file to use excel features on the data.   Below function shows how to convert an csv file into excel file and vice versa. We can also convert to other formats based on constants Here constant value 23 is used to create a csv file and constant -4143 to save a file as xls file. Once the destination file is created, we can delete the source file as shown below.  In case of any issue in understanding the code, please add in comment section Call func_ConversionCSVExcel("E:\Test.csv", "E:\Test_converted.xls", "csvtoexcel") Public Function func_ConversionCSVExcel(strSrcFile, strDestFile, Conversion) on error resume next Set objExcel = CreateObject("Excel.application") set objExcelBook = objExcel.Workbooks.Open(strSrcFile) objExcel.application.visible=false objExcel.application.displayalerts=