Selenium Tutorial : Appendix
alertRetrieves the message of a JavaScript alert, or fail if there were no alerts
alertWhether an alert occurred
all_window_idsReturns the IDs of all windows that the browser knows about
all_window_namesReturns the names of all windows that the browser knows about
all_window_titlesReturns the titles of all windows that the browser knows about
body_textGets the entire text of the page
browser_network_traffic(format = :plain)Network traffic seen by the browser
checked?(locator)Returns whether a toggle-button (checkbox/radio) is checked
click(locator, options={})Clicks on a link, button, checkbox or radio button. Using options you can automatically wait for an event to happen after the click. e.g
click "a_locator", :wait_for => :pageWill wait for a new page to load
click "a_locator", :wait_for => :popup, :window => "a window id"Will wait for a new popup window to appear. Also selects the popup window for you provide
:select => trueclick "a_locator", :wait_for => :ajaxWill wait for all ajax requests to be completed using semantics of default javascript framework
click "a_locator", :wait_for => :ajax, :javascript_framework => :jqueryWill wait for all ajax requests to be completed overriding default javascript framework
click "a_locator", :wait_for => :effectsWill wait for all javascript effects to be rendered using semantics of default javascript framework
click "a_locator", :wait_for => :effects, :javascript_framework => :prototypeWill wait for all javascript effects to be rendered overriding default javascript framework
click "a_locator", :wait_for => :element, :element => "new_element_id"Will wait for an element to be present/appear
click "a_locator", :wait_for => :no_element, :element => "new_element_id"Will wait for an element to be not be present/disappear
click "a_locator", :wait_for => :text, :text => "some text"Will wait for some text to be present/appear
click "a_locator", :wait_for => :text, :text => /A Regexp/Will wait for some text to be present/appear using a regular expression
click "a_locator", :wait_for => :text, :element => "a_locator", :text => "some text"Will wait for the content of a_locator to be some text
click "a_locator", :wait_for => :no_text, :text => "some text"Will wait for the text to be not be present/disappear
click "a_locator", :wait_for => :no_text, :text => /A Regexp/Will wait for the text to be not be present/disappear
click "a_locator", :wait_for => :no_text, :element => "a_locator", :text => "some text"Will wait for the content of a_locator to not be some text
click "a_locator", :wait_for => :value, :element => "a_locator", :value => "some value"Will wait for the field value of a_locator to be some value
click "a_locator", :wait_for => :no_value, :element => "a_locator", :value => "some value"will wait for the field value of a_locator to not be some value
click "a_locator", :wait_for => :visible, :element => "a_locator"will wait for the element to be visible on the page
click "a_locator", :wait_for => :not_visible, :element => "a_locator"will wait for the element to be not visible anymore on the page
click "a_locator", :wait_for => :condition, :javascript => "some expression"Will wait for the javascript expression to be true Using options you can also define an explicit timeout (
:timeout_in_secondskey). Otherwise the default driver timeout is used
confirmationMessage of a JavaScript confirmation dialog generated during the previous action
confirmation?Whether a confirmation has been auto-acknoledged (i.e. confirm() been called)
cookie(name)Value of the cookie with the specified name, or error if the cookie is not present
cookie?(name)Returns true if a cookie with the specified name is present, or false otherwise
cookiesReturn all cookies for the current page under test
create_cookie(name_value_pair, options="")Create a new cookie, see docs for details
delete_cookie(name, options="")Delete a named cookie, see docs for detail
element?(locator)Verifies that the specified element is somewhere on the page
execution_delayGet delay following each selenium operation, in milliseconds
execution_delay=(delay)Pause delay following each selenium operation
field(locator)Gets the (whitespace-trimmed) value of an input field; "on" or "off" for checkboxes
go_back(options={})Simulates the user clicking the "back" button on their browser
js_eval(script)Returns the result of evaluating the specified JavaScript snippet whithin the browser
locationReturns the absolute URL of the current page
promptMessage of a JavaScript question prompt dialog generated during the previous action
prompt?Whether a prompt occurred
remote_control_timeout_in_seconds=(timeout)Set the Remote Control timeout
table_cell_text(tableCellAddress)Retrieves the text from a cell of a table. The
tableCellAddresssyntax istableLocator.row.column. Row and column start at 0text(locator)Text content of an HTML element
text?(pattern)Verifies that the specified text pattern appears somewhere on the rendered page
text_content(locator)Alias for text
titleReturn the title of the current HTML pages
value(locator)Alias for field
visible?(locator)Determines if the specified element is visible. Fails if the element is not present
wait_for(options)Flexible wait semantics. Wait is happening browser side. Useful for testing AJAX applications
wait :wait_for => :pageWill wait for a new page to load
wait :wait_for => :popup, :window => "a window id"Will wait for a new popup window to appear. Also selects the popup window for you provide
:select => truewait :wait_for => :ajaxWill wait for all ajax requests to be completed using semantics of default javascript framework
wait :wait_for => :ajax, :javascript_framework => :jqueryWill wait for all ajax requests to be completed overriding default javascript framework
wait :wait_for => :effectsWill wait for all javascript effects to be rendered using semantics of default javascript framework
wait :wait_for => :effects, :javascript_framework => :prototypeWill wait for all javascript effects to be rendered overriding default javascript framework
wait :wait_for => :element, :element => "new_element_id"Will wait for an element to be present/appear
wait :wait_for => :no_element, :element => "new_element_id"Will wait for an element to be not be present/disappear
wait :wait_for => :text, :text => "some text"Will wait for some text to be present/appear
wait :wait_for => :text, :text => /A Regexp/Will wait for some text to be present/appear
wait :wait_for => :text, :element => "a_locator", :text => "some text"Will wait for the content of "a_locator" to be "some text"
wait :wait_for => :no_text, :text => "some text"Will wait for the text to be not be present/disappear
wait :wait_for => :no_text, :text => /A Regexp/Will wait for the text to be not be present/disappear
wait :wait_for => :no_text, :element => "a_locator", :text => "some text"Will wait for the content of "a_locator" to not be "some text"
wait :wait_for => :value, :element => "a_locator", :value => "some value"Will wait for the field value of "a_locator" to be "some value"
wait :wait_for => :no_value, :element => "a_locator", :value => "some value"Will wait for the field value of "a_locator" to not be "some value"
wait :wait_for => :condition, :javascript => "some expression"Will wait for the javascript expression to be true. Using options you can override the default framework timeout
wait_for_condition(script, timeout_in_seconds = nil)Runs the specified JavaScript snippet repeatedly until it evaluates to "true"
wait_for_page(timeout_in_seconds=nil)Waits for a new page to load
wait_for_page_to_load(timeout_in_seconds=nil)Alias for wait_for_page
wait_for_popup(window_id, timeout_in_seconds=nil)Waits for a popup window to appear and load
14.2.1. Section 6.10, “Quiz”
What do these locators do?
ol[id="list"]//liall <li> elements one or more levels deep in the <ol id="list"> element
ol[id="list"]/*/liall <li> element that are grandchildren of <ol>
document.forms[0]get the first form on the page
p.this_classThe first
<p>element that is of the that_class css classdiv span#thisidThe
<span>element with the idthisidthat is inside a divdiv.sidenav li > a [name=this_name]Matches the
<a>element that has anameattribute set to this_name when inside a list item grandchildren of the<div>that has the class sidenav/html/body/span[@id="thatspan"]the span with the id thatspan
//span[@id="thatspan"]the same thing!
14.2.2. Section 6.11.1, “Quiz”
Why use an XPath locator?
Each time you refresh the page, the id of the Delete link control change. We need to use a locator based on the structure of the page.
GNU\Linux: use your package manager
-
Ubuntu:
aptitude install ruby
-
Ubuntu:
Windows: install Ruby 1.8 with RubyInstaller
-
available at
http://rubyinstaller.org/downloads/
-
available at
- MacOS: install ruby with a port manager like MacPorts or Fink