Frequently used Selenium Commands

So I’ve been dabling with Selenium again…I love open source, but the lack of documentation is very frustrating. Hitting F1 in Loadrunner was taken for granted, so if I find something useful, as a fellow open-sourcer, I’m going to share it. Hopefully this can be of some use to you all.
Enjoy!

assignId(“Locator”,”String”) Temporarily sets the “id” attribute of the specified element
capture Screenshot (“File name”) Captures a PNG screenshot to thespecified file.
Check(“Locator”) Check a toggle-button(checkbox/radio)
click(“Locator”) Clicks on a link, button, checkboxor radio button.
clickAt(“Locator”,”Coordinate String”) Clicks on a link, button, checkboxor radio button.
close() Simulates the user clicking the”close” button in the title bar of a popup window or tab.
doubleClick(“Locator”) Double clicks on a link, button,checkbox or radio button.
doubleClickAt(“Locator”,”Coordinate String”) Double clicks on a link, button,checkbox or radio button.
getAlert() Retrieves the message of aJavaScript alert generated during the previous action, or fail if there were no alerts.
getAllButtons() Returns the IDs of all buttons onthe page.
getAllFields() Returns the IDs of all input fieldson the page.
getAllLinks() Returns the IDs of all links on the page.
getAllWindowIds() Returns the IDs of all windows that the browser knows about.
getAllWindowNames() Returns the names of all windows that the browser knows about.
getAllWindowTitles() Returns the titles of all windows that the browser knows about.
getAttribute(“Attribute Locator”) Gets the value of an element attribute.
getBodyText() Gets the entire text of the page.
getConfirmation() Retrieves the message of a JavaScript confirmation dialog generated during the previous action.
getCookie() Return all cookies of the current page under test.
getElementHeight(“Locator”) Retrieves the height of an element
getElementPositionLeft(“Locator”) Retrieves the horizontal position of an element
getElementPositionTop(“Locator”) Retrieves the vertical position of an element
getElementWidth(“Locator”) Retrieves the width of an element
getEval(“JS Expression”) Gets the result of evaluating the specified JavaScript snippet.
getLocation() Gets the absolute URL of the current page.
getMouseSpeed() Returns the number of pixels between “mousemove” events during dragAndDrop commands (default=10).
getPrompt() Retrieves the message of a JavaScript question prompt dialog generated during the previous action.
getSelectedId(“Select Locator”) Gets option element ID for selected option in the specified select element.
getSelectedIds(“Select Locator”) Gets all option element IDs for selected options in the specified select or multi-select element.
getSelectedIndex(“Select Locator”) Gets option index (option number, starting at 0) for selected option in the specified select element.
getSelectedIndexes(“Select Locator”) Gets all option indexes (option number, starting at 0) for selected options in the specified select or multi-select element.
getSelectedLable(“Select Locator”) Gets option label (visible text) for selected option in the specified select element.
getSelectedLables(“Select Locator”) Gets all option labels (visible text) for selected options in the specified select or multi-select element.
getSelectedValue(“Select Locator”) Gets option value (value attribute) for selected option in the specified select element.
getSelectedValues(“Select Locator”) Gets all option values (value attributes) for selected options in the specified select or multi-select element.
getSelectOptions(“Select Locator”) Gets all option labels in the specified select drop-down.
getSpeed() Get execution speed (i.e., get the millisecond length of the delay following each selenium operation).
getTable(“Table Cell Address”) Gets the text from a cell of a table.
getText(“Locator”) Gets the text of an element.
getTitle() Gets the title of the current page.
getValue(“Locator”) Gets the (whitespace-trimmed) value of an input field (or anything else with a value parameter).
get Whether This Frame MatchFrameExpression(“Current Frame”,”Target”) Determine whether current/locator identify the frame containing this running code
get Whether This Window MatchWindowExpression(“CurrentWindow”,”Target”) Determine whether currentWindow String plus target identify the window containing this running code.
goBack() Simulates the user clicking the “back” button on their browser.
highlight(“Locator”) Briefly changes the backgroundColor of the specified element yellow.
isAlertPresent() Has an alert occurred?
isChecked(“Locator”) Gets whether a toggle-button (checkbox/radio) is checked.
isConfirmationPresent() Has confirm() been called?
isEditable(“Locator”) Determines whether the specified input element is editable, ie hasn’t been disabled.
isElementPresent(“Locator”) Verifies that the specified element is somewhere on the page.
isPromptPresent() Has a prompt occurred?
isSomethingSelected(“Locator”) Determines whether some option in a drop-down menu is selected.
isTextPresent(“Pattern”) Verifies that the specified text pattern appears somewhere on the rendered page shown to the user.
isVisible(“Locator”) Determines if the specified element is visible.
open(“URL”) Opens an URL in the test frame.
openWindow(“URL”,”WindowID”) Opens a popup window (if a window with that ID isn’t already open).
refresh() Simulates the user clicking the “Refresh” button on their browser.
removeAllSelections(“Locator”) Unselects all of the selected options in a multi-select element.
removeSelection(“Locator”,”Option Locator”) Remove a selection from the set of selected options in a multi-select element using an option locator.
select(“Select Locator”,”Option Locator”) Select an option from a drop-down using an option locator.
selectFrame(“Locator”) Selects a frame within the current window.
selectWindow(“WindowID”) Selects a popup window; once a popup window has been selected, all commands go to that window.
setSpeed(“Value”) Set execution speed (i.e., set the millisecond length of a delay which will follow each selenium operation).
setTimeout(“Time”) Specifies the amount of time that Selenium will wait for actions to complete.
start() Launches the browser with a new Selenium session
stop() Ends the test session, killing the browser
submit(“Form Locator”) Submit the specified form.
type(“Locator”,”Value”) Sets the value of an input field, as though you typed it in.
unCheck(“Locator”) Uncheck a toggle-button (checkbox/radio)
waitForCondition(“JavaScript”,”Timeout”) Runs the specified JavaScript snippet repeatedly until it evaluates to “true”.
waitForFrameToLoad(“Frame Address”,”Timeout”) Waits for a new frame to load.
waitForPageToLoad(“Timeout”) Waits for a new page to load.
waitForPopUp(“WindowID”,”Timeout”) Waits for a popup window to appear and load up.
windowFocus() Gives focus to the currently selected window
windowMaximize() Resize currently selected window to take up the entire screen


4 Comments

  • vishwanath
    March 3, 2010 - 12:07 am | Permalink

    The commands which u have listed are very helpful to me thanks …….

  • Akash
    August 15, 2010 - 11:46 pm | Permalink

    Hey…Nice collection….dude…….

  • Aneesh
    April 9, 2012 - 12:22 am | Permalink

    You can find all the operations supported by selenium in the API class under package com.thoughtworks.selenium

  • Srikanth
    October 14, 2012 - 11:20 pm | Permalink

    Good information

  • Leave a Reply

    Your email address will not be published. Required fields are marked *

    *

    You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>