Module: Selenium::Client::Idiomatic
- Included in:
- Base
- Defined in:
- lib/selenium/client/idiomatic.rb
Overview
Provide a more idiomatic API than the generated Ruby driver.
Work in progress…
Instance Method Summary collapse
- #actual_timeout_in_milliseconds(timeout_in_seconds) ⇒ Object
-
#alert ⇒ Object
Retrieves the message of a JavaScript alert generated during the previous action, or fail if there were no alerts.
-
#alert? ⇒ Boolean
Whether an alert occurred.
-
#all_window_ids ⇒ Object
Returns the IDs of all windows that the browser knows about.
-
#all_window_names ⇒ Object
Returns the names of all windows that the browser knows about.
-
#all_window_titles ⇒ Object
Returns the titles of all windows that the browser knows about.
-
#body_text ⇒ Object
Gets the entire text of the page.
-
#browser_network_traffic(format = :plain) ⇒ Object
Returns a string representation of the network traffic seen by the browser, including headers, AJAX requests, status codes, and timings.
-
#browser_xpath_library=(library_name) ⇒ Object
Allows choice of a specific XPath libraries for Xpath evualuation in the browser (e.g. to resolve XPath locators).
-
#checked?(locator) ⇒ Boolean
Returns whether a toggle-button (checkbox/radio) is checked.
-
#click(locator, options = {}) ⇒ Object
Clicks on a link, button, checkbox or radio button.
-
#confirmation ⇒ Object
Retrieves the message of a JavaScript confirmation dialog generated during the previous action.
-
#confirmation? ⇒ Boolean
Whether a confirmation has been auto-acknoledged (i.e. confirm() been called).
-
#cookie(name) ⇒ Object
Returns the value of the cookie with the specified name, or throws an error if the cookie is not present.
-
#cookie?(name) ⇒ Boolean
Returns true if a cookie with the specified name is present, or false otherwise.
-
#cookies ⇒ Object
Return all cookies for the current page under test.
-
#create_cookie(name_value_pair, options = "") ⇒ Object
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.
-
#delete_cookie(name, options = "") ⇒ Object
Delete a named cookie with specified path and domain.
-
#element?(locator) ⇒ Boolean
Verifies that the specified element is somewhere on the page.
-
#execution_delay ⇒ Object
Get execution delay in milliseconds, i.e.
-
#execution_delay=(delay_in_milliseconds) ⇒ Object
Set the execution delay in milliseconds, i.e.
-
#field(locator) ⇒ Object
Gets the (whitespace-trimmed) value of an input field (or anything else with a value parameter).
-
#go_back(options = {}) ⇒ Object
Simulates the user clicking the “back” button on their browser.
-
#highlight_located_element=(enabled) ⇒ Object
Turn on/off the automatic hightlighting of the element driven or inspected by Selenium core.
-
#js_eval(script) ⇒ Object
Returns the result of evaluating the specified JavaScript snippet whithin the browser.
-
#location ⇒ Object
Returns the absolute URL of the current page.
-
#prompt ⇒ Object
Retrieves the message of a JavaScript question prompt dialog generated during the previous action.
-
#prompt? ⇒ Boolean
Whether a prompt occurred.
-
#remote_control_timeout_in_seconds=(timeout_in_seconds) ⇒ Object
Set the Remote Control timeout (as opposed to the client side driver timeout).
-
#table_cell_text(tableCellAddress) ⇒ Object
Returns the text from a cell of a table.
-
#text(locator) ⇒ Object
(also: #text_content)
Return the text content of an HTML element (rendered text shown to the user).
-
#text?(pattern) ⇒ Boolean
Verifies that the specified text pattern appears somewhere on the rendered page shown to the user.
-
#title ⇒ Object
Return the title of the current HTML page.
-
#value(locator) ⇒ Object
Alias for
field
. -
#visible?(locator) ⇒ Boolean
Determines if the specified element is visible.
-
#wait_for(options) ⇒ Object
Flexible wait semantics.
-
#wait_for_condition(script, timeout_in_seconds = nil) ⇒ Object
Runs the specified JavaScript snippet repeatedly until it evaluates to “true”.
-
#wait_for_page(timeout_in_seconds = nil) ⇒ Object
(also: #wait_for_page_to_load)
Waits for a new page to load.
-
#wait_for_popup(window_id, timeout_in_seconds = nil) ⇒ Object
Waits for a popup window to appear and load up.
Instance Method Details
#actual_timeout_in_milliseconds(timeout_in_seconds) ⇒ Object
499 500 501 502 503 |
# File 'lib/selenium/client/idiomatic.rb', line 499 def actual_timeout_in_milliseconds(timeout_in_seconds) actual_timeout = (timeout_in_seconds || default_timeout_in_seconds).to_i actual_timeout * 1000 end |
#alert ⇒ Object
Retrieves the message of a JavaScript alert generated during the previous action, or fail if there were no alerts.
Getting an alert has the same effect as manually clicking OK. If an alert is generated but you do not consume it with getAlert, the next Selenium action will fail.
Under Selenium, JavaScript alerts will NOT pop up a visible alert dialog.
Selenium does NOT support JavaScript alerts that are generated in a page’s onload() event handler. In this case a visible dialog WILL be generated and Selenium will hang until someone manually clicks OK.
239 240 241 |
# File 'lib/selenium/client/idiomatic.rb', line 239 def alert string_command "getAlert" end |
#alert? ⇒ Boolean
Whether an alert occurred
221 222 223 |
# File 'lib/selenium/client/idiomatic.rb', line 221 def alert? boolean_command "isAlertPresent" end |
#all_window_ids ⇒ Object
Returns the IDs of all windows that the browser knows about.
427 428 429 |
# File 'lib/selenium/client/idiomatic.rb', line 427 def all_window_ids string_array_command "getAllWindowIds" end |
#all_window_names ⇒ Object
Returns the names of all windows that the browser knows about.
433 434 435 |
# File 'lib/selenium/client/idiomatic.rb', line 433 def all_window_names string_array_command "getAllWindowNames" end |
#all_window_titles ⇒ Object
Returns the titles of all windows that the browser knows about.
439 440 441 |
# File 'lib/selenium/client/idiomatic.rb', line 439 def all_window_titles string_array_command "getAllWindowTitles" end |
#body_text ⇒ Object
Gets the entire text of the page.
134 135 136 |
# File 'lib/selenium/client/idiomatic.rb', line 134 def body_text string_command "getBodyText" end |
#browser_network_traffic(format = :plain) ⇒ Object
Returns a string representation of the network traffic seen by the browser, including headers, AJAX requests, status codes, and timings. When this function is called, the traffic log is cleared, so the returned content is only the traffic seen since the last call.
The network traffic is returned in the format it was requested. Valid values are: :json, :xml, or :plain.
Warning: For browser_network_traffic to work you need to start your browser session with the option “captureNetworkTraffic=true”, which will force ALL traffic to go to the Remote Control proxy even for more efficient browser modes like ‘*firefox` and `*safari`.
455 456 457 458 459 460 |
# File 'lib/selenium/client/idiomatic.rb', line 455 def browser_network_traffic(format = :plain) raise "format must be :plain, :json, or :xml" \ unless [:plain, :json, :xml].include?(format) remote_control_command "captureNetworkTraffic", [format.to_s] end |
#browser_xpath_library=(library_name) ⇒ Object
Allows choice of a specific XPath libraries for Xpath evualuation in the browser (e.g. to resolve XPath locators).
‘library_name’ can be:
* :ajaxslt : Google's library
* :javascript-xpath : Cybozu Labs' faster library
* :default : Selenium default library.
469 470 471 472 473 |
# File 'lib/selenium/client/idiomatic.rb', line 469 def browser_xpath_library=(library_name) raise "library name must be :ajaxslt, :javascript-xpath, or :default" \ unless [:ajaxslt, :'javascript-xpath', :default].include?(library_name) remote_control_command "useXpathLibrary", [library_name.to_s] end |
#checked?(locator) ⇒ Boolean
Returns whether a toggle-button (checkbox/radio) is checked. Fails if the specified element doesn’t exist or isn’t a toggle-button.
-
‘locator’ is an element locator pointing to a checkbox or radio button
216 217 218 |
# File 'lib/selenium/client/idiomatic.rb', line 216 def checked?(locator) boolean_command "isChecked", [locator,] end |
#click(locator, options = {}) ⇒ Object
Clicks on a link, button, checkbox or radio button.
‘locator’ is an element locator
Using ‘options’ you can automatically wait for an event to happen after the click. e.g.
-
click “a_locator”, :wait_for => :page # will 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 => true`
-
click “a_locator”, :wait_for => :ajax # will wait for all ajax requests to be completed using semantics of default javascript framework
-
click “a_locator”, :wait_for => :ajax, :javascript_framework => :jquery # will wait for all ajax requests to be completed overriding default javascript framework
-
click “a_locator”, :wait_for => :effects # will wait for all javascript effects to be rendered using semantics of default javascript framework
-
click “a_locator”, :wait_for => :effects, :javascript_framework => :prototype # will 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
-
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 element to be visible
-
click “a_locator”, :wait_for => :not_visible, :element => ‘a_locator’ # will wait for element to not be visible
-
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_seconds key). Otherwise the default driver timeout is used.
167 168 169 170 |
# File 'lib/selenium/client/idiomatic.rb', line 167 def click(locator, ={}) remote_control_command "click", [locator,] wait_for end |
#confirmation ⇒ Object
Retrieves the message of a JavaScript confirmation dialog generated during the previous action.
By default, the confirm function will return true, having the same effect as manually clicking OK. This can be changed by prior execution of the chooseCancelOnNextConfirmation command.
If an confirmation is generated but you do not consume it with getConfirmation, the next Selenium action will fail.
NOTE: under Selenium, JavaScript confirmations will NOT pop up a visible dialog.
NOTE: Selenium does NOT support JavaScript confirmations that are generated in a page’s onload() event handler. In this case a visible dialog WILL be generated and Selenium will hang until you manually click OK.
265 266 267 |
# File 'lib/selenium/client/idiomatic.rb', line 265 def confirmation string_command "getConfirmation" end |
#confirmation? ⇒ Boolean
Whether a confirmation has been auto-acknoledged (i.e. confirm() been called)
244 245 246 |
# File 'lib/selenium/client/idiomatic.rb', line 244 def confirmation? boolean_command "isConfirmationPresent" end |
#cookie(name) ⇒ Object
Returns the value of the cookie with the specified name, or throws an error if the cookie is not present.
‘name’ is the name of the cookie
381 382 383 |
# File 'lib/selenium/client/idiomatic.rb', line 381 def (name) string_command "getCookieByName", [name,] end |
#cookie?(name) ⇒ Boolean
Returns true if a cookie with the specified name is present, or false otherwise.
‘name’ is the name of the cookie
388 389 390 |
# File 'lib/selenium/client/idiomatic.rb', line 388 def (name) boolean_command "isCookiePresent", [name,] end |
#cookies ⇒ Object
Return all cookies for the current page under test.
374 375 376 |
# File 'lib/selenium/client/idiomatic.rb', line 374 def string_command "getCookie" end |
#create_cookie(name_value_pair, options = "") ⇒ Object
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’ is name and value of the cookie in a format “name=value” ‘optionsString’ is options for the cookie. Currently supported options include ‘path’, ‘max_age’ and ‘domain’. the optionsString’s format is “path=/path/, max_age=60, domain=.foo.com”. The order of options are irrelevant, the unit of the value of ‘max_age’ is second. Note that specifying a domain that isn’t a subset of the current domain will usually fail.
398 399 400 401 402 403 |
# File 'lib/selenium/client/idiomatic.rb', line 398 def (name_value_pair, ="") if .kind_of? Hash = .keys.collect {|key| "#{key}=#{[key]}" }.sort.join(", ") end remote_control_command "createCookie", [name_value_pair,,] end |
#delete_cookie(name, options = "") ⇒ Object
Delete a named cookie with specified path and domain. Be careful; to delete a cookie, you need to delete it using the exact same path and domain that were used to create the cookie. If the path is wrong, or the domain is wrong, the cookie simply won’t be deleted. Also note that specifying a domain that isn’t a subset of the current domain will usually fail.
Since there’s no way to discover at runtime the original path and domain of a given cookie, we’ve added an option called ‘recurse’ to try all sub-domains of the current domain with all paths that are a subset of the current path. Beware; this option can be slow. In big-O notation, it operates in O(n*m) time, where n is the number of dots in the domain name and m is the number of slashes in the path.
‘name’ is the name of the cookie to be deleted ‘optionsString’ is options for the cookie. Currently supported options include ‘path’, ‘domain’ and ‘recurse.’ The optionsString’s format is “path=/path/, domain=.foo.com, recurse=true”. The order of options are irrelevant. Note that specifying a domain that isn’t a subset of the current domain will usually fail.
418 419 420 421 422 423 424 |
# File 'lib/selenium/client/idiomatic.rb', line 418 def (name, ="") if .kind_of? Hash ordered_keys = .keys.sort {|a,b| a.to_s <=> b.to_s } = ordered_keys.collect {|key| "#{key}=#{[key]}" }.join(", ") end remote_control_command "deleteCookie", [name,,] end |
#element?(locator) ⇒ Boolean
Verifies that the specified element is somewhere on the page.
-
‘locator’ is an element locator
182 183 184 |
# File 'lib/selenium/client/idiomatic.rb', line 182 def element?(locator) boolean_command "isElementPresent", [locator,] end |
#execution_delay ⇒ Object
Get execution delay in milliseconds, i.e. a pause delay following each selenium operation. By default, there is no such delay (value is 0).
487 488 489 |
# File 'lib/selenium/client/idiomatic.rb', line 487 def execution_delay string_command "getSpeed" end |
#execution_delay=(delay_in_milliseconds) ⇒ Object
Set the execution delay in milliseconds, i.e. a pause delay following each selenium operation. By default, there is no such delay.
Setting an execution can be useful to troubleshoot or capture videos
495 496 497 |
# File 'lib/selenium/client/idiomatic.rb', line 495 def execution_delay=(delay_in_milliseconds) remote_control_command "setSpeed", [delay_in_milliseconds] end |
#field(locator) ⇒ Object
Gets the (whitespace-trimmed) value of an input field (or anything else with a value parameter). For checkbox/radio elements, the value will be “on” or “off” depending on whether the element is checked or not.
-
‘locator’ is an element locator
203 204 205 |
# File 'lib/selenium/client/idiomatic.rb', line 203 def field(locator) string_command "getValue", [locator,] end |
#go_back(options = {}) ⇒ Object
Simulates the user clicking the “back” button on their browser. Using ‘options’ you can automatically wait for an event to happen after the click. e.g.
-
go_back :wait_for => :page # will wait for a new page to load
-
go_back :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 => true`
-
go_back :wait_for => :ajax # will wait for all ajax requests to be completed using semantics of default javascript framework
-
go_back :wait_for => :ajax, :javascript_framework => :jquery # will wait for all ajax requests to be completed overriding default javascript framework
-
go_back :wait_for => :effects # will wait for all javascript effects to be rendered using semantics of default javascript framework
-
go_back :wait_for => :effects, :javascript_framework => :prototype # will wait for all javascript effects to be rendered overriding default javascript framework
-
go_back :wait_for => :element, :element => ‘new_element_id’ # will wait for an element to be present/appear
-
go_back :wait_for => :no_element, :element => ‘new_element_id’ # will wait for an element to be not be present/disappear
-
go_back :wait_for => :text, :text => ‘some text’ # will wait for some text to be present/appear
-
go_back “a_locator”, :wait_for => :text, :text => /A Regexp/ # will wait for some text to be present/appear
-
go_back :wait_for => :text, :element => ‘a_locator’, :text => ‘some text’ # will wait for the content of ‘a_locator’ to be ‘some text’
-
go_back :wait_for => :no_text, :text => ‘some text’ # will wait for the text to be not be present/disappear
-
go_back “a_locator”, :wait_for => :no_text, :text => /A Regexp/ # will wait for the text to be not be present/disappear
-
go_back :wait_for => :no_text, :element => ‘a_locator’, :text => ‘some text’ # will wait for the content of ‘a_locator’ to not be ‘some text’
-
go_back :wait_for => :condition, :javascript => ‘some expression’ # will wait for the javascript expression to be true
-
go_back :wait_for => :value, :element => ‘a_locator’, :value => ‘some value’ # will wait for the field value of ‘a_locator’ to be ‘some value’
-
go_back :wait_for => :visible, :element => ‘a_locator’ # will wait for element to be visible
-
go_back :wait_for => :not_visible, :element => ‘a_locator’ # will wait for element to not be visible
-
go_back :wait_for => :no_value, :element => ‘a_locator’, :value => ‘some value’ # will wait for the field value of ‘a_locator’ to not be ‘some value’
Using options you can also define an explicit timeout (:timeout_in_seconds key). Otherwise the default driver timeout is used.
368 369 370 371 |
# File 'lib/selenium/client/idiomatic.rb', line 368 def go_back(={}) remote_control_command "goBack" wait_for end |
#highlight_located_element=(enabled) ⇒ Object
Turn on/off the automatic hightlighting of the element driven or inspected by Selenium core. Useful when recording videos
479 480 481 482 |
# File 'lib/selenium/client/idiomatic.rb', line 479 def highlight_located_element=(enabled) boolean = (true == enabled) js_eval "selenium.browserbot.shouldHighlightLocatedElement = #{boolean}" end |
#js_eval(script) ⇒ Object
Returns the result of evaluating the specified JavaScript snippet whithin the browser.
The snippet may have multiple lines, but only the result of the last line will be returned.
Note that, by default, the snippet will run in the context of the “selenium” object itself, so this
will refer to the Selenium object. Use window
to refer to the window of your application, e.g. window.document.getElementById('foo')
If you need to use a locator to refer to a single element in your application page, you can use this.browserbot.findElement("id=foo")
where “id=foo” is your locator.
-
‘script’ is the JavaScript snippet to run
302 303 304 |
# File 'lib/selenium/client/idiomatic.rb', line 302 def js_eval(script) string_command "getEval", [script,] end |
#location ⇒ Object
Returns the absolute URL of the current page.
49 50 51 |
# File 'lib/selenium/client/idiomatic.rb', line 49 def location string_command "getLocation" end |
#prompt ⇒ Object
Retrieves the message of a JavaScript question prompt dialog generated during the previous action.
Successful handling of the prompt requires prior execution of the answerOnNextPrompt command. If a prompt is generated but you do not get/verify it, the next Selenium action will fail.
NOTE: under Selenium, JavaScript prompts will NOT pop up a visible dialog.
NOTE: Selenium does NOT support JavaScript prompts that are generated in a page’s onload() event handler. In this case a visible dialog WILL be generated and Selenium will hang until someone manually clicks OK.
287 288 289 |
# File 'lib/selenium/client/idiomatic.rb', line 287 def prompt string_command "getPrompt" end |
#prompt? ⇒ Boolean
Whether a prompt occurred
270 271 272 |
# File 'lib/selenium/client/idiomatic.rb', line 270 def prompt? boolean_command "isPromptPresent" end |
#remote_control_timeout_in_seconds=(timeout_in_seconds) ⇒ Object
Set the Remote Control timeout (as opposed to the client side driver timeout). This timout specifies the amount of time that Selenium Core will wait for actions to complete.
The default timeout is 30 seconds. ‘timeout’ is a timeout in seconds, after which the action will return with an error
Actions that require waiting include “open” and the “waitFor*” actions.
313 314 315 |
# File 'lib/selenium/client/idiomatic.rb', line 313 def remote_control_timeout_in_seconds=(timeout_in_seconds) remote_control_command "setTimeout", [actual_timeout_in_milliseconds(timeout_in_seconds),] end |
#table_cell_text(tableCellAddress) ⇒ Object
Returns the text from a cell of a table. The cellAddress syntax tableLocator.row.column, where row and column start at 0.
-
‘tableCellAddress’ is a cell address, e.g. “foo.1.4”
321 322 323 |
# File 'lib/selenium/client/idiomatic.rb', line 321 def table_cell_text(tableCellAddress) string_command "getTable", [tableCellAddress,] end |
#text(locator) ⇒ Object Also known as: text_content
Return the text content of an HTML element (rendered text shown to the user). Works for any HTML element that contains text.
This command uses either the textContent (Mozilla-like browsers) or the innerText (IE-like browsers) of the element, which is the rendered text shown to the user.
-
‘locator’ is an Selenium element locator
38 39 40 |
# File 'lib/selenium/client/idiomatic.rb', line 38 def text(locator) string_command "getText", [locator,] end |
#text?(pattern) ⇒ Boolean
Verifies that the specified text pattern appears somewhere on the rendered page shown to the user.
-
‘pattern’ is a pattern to match with the text of the page
175 176 177 |
# File 'lib/selenium/client/idiomatic.rb', line 175 def text?(pattern) boolean_command "isTextPresent", [pattern,] end |
#title ⇒ Object
Return the title of the current HTML page.
44 45 46 |
# File 'lib/selenium/client/idiomatic.rb', line 44 def title string_command "getTitle" end |
#value(locator) ⇒ Object
Alias for field
208 209 210 |
# File 'lib/selenium/client/idiomatic.rb', line 208 def value(locator) field locator end |
#visible?(locator) ⇒ Boolean
Determines if the specified element is visible. An element can be rendered invisible by setting the CSS “visibility” property to “hidden”, or the “display” property to “none”, either for the element itself or one if its ancestors. This method will fail if the element is not present.
‘locator’ is an element locator
193 194 195 |
# File 'lib/selenium/client/idiomatic.rb', line 193 def visible?(locator) boolean_command "isVisible", [locator,] end |
#wait_for(options) ⇒ Object
Flexible wait semantics. ait is happening browser side. Useful for testing AJAX application.
-
wait :wait_for => :page # will 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 => true`
-
wait :wait_for => :ajax # will wait for all ajax requests to be completed using semantics of default javascript framework
-
wait :wait_for => :ajax, :javascript_framework => :jquery # will wait for all ajax requests to be completed overriding default javascript framework
-
wait :wait_for => :effects # will wait for all javascript effects to be rendered using semantics of default javascript framework
-
wait :wait_for => :effects, :javascript_framework => :prototype # will 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 => :visible, :element => ‘a_locator’ # will wait for element to be visible
-
wait :wait_for => :not_visible, :element => ‘a_locator’ # will wait for element to not be visible
-
wait :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_seconds key). Otherwise the default driver timeout is used.
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/selenium/client/idiomatic.rb', line 102 def wait_for() if [:wait_for] == :page wait_for_page [:timeout_in_seconds] elsif [:wait_for] == :ajax wait_for_ajax elsif [:wait_for] == :element wait_for_element [:element], elsif [:wait_for] == :no_element wait_for_no_element [:element], elsif [:wait_for] == :text wait_for_text [:text], elsif [:wait_for] == :no_text wait_for_no_text [:text], elsif [:wait_for] == :effects wait_for_effects elsif [:wait_for] == :popup wait_for_popup [:window], [:timeout_in_seconds] select_window [:window] if [:select] elsif [:wait_for] == :value wait_for_field_value [:element], [:value], elsif [:wait_for] == :no_value wait_for_no_field_value [:element], [:value], elsif [:wait_for] == :visible wait_for_visible [:element], elsif [:wait_for] == :not_visible wait_for_not_visible [:element], elsif [:wait_for] == :condition wait_for_condition [:javascript], [:timeout_in_seconds] end end |
#wait_for_condition(script, timeout_in_seconds = nil) ⇒ Object
Runs the specified JavaScript snippet repeatedly until it evaluates to “true”. The snippet may have multiple lines, but only the result of the last line will be considered.
Note that, by default, the snippet will be run in the runner’s test window, not in the window of your application. To get the window of your application, you can use the JavaScript snippet selenium.browserbot.getCurrentWindow()
, and then run your JavaScript in there
-
‘script’ is the JavaScript snippet to run
-
‘timeout_in_seconds’ is a timeout in seconds, after which this command will return with an error
337 338 339 340 |
# File 'lib/selenium/client/idiomatic.rb', line 337 def wait_for_condition(script, timeout_in_seconds = nil) remote_control_command "waitForCondition", [script, actual_timeout_in_milliseconds(timeout_in_seconds),] end |
#wait_for_page(timeout_in_seconds = nil) ⇒ Object Also known as: wait_for_page_to_load
Waits for a new page to load.
Selenium constantly keeps track of new pages loading, and sets a “newPageLoaded” flag when it first notices a page load. Running any other Selenium command after turns the flag to false. Hence, if you want to wait for a page to load, you must wait immediately after a Selenium command that caused a page-load.
-
‘timeout_in_seconds’ is a timeout in seconds, after which this command will return with an error
63 64 65 66 |
# File 'lib/selenium/client/idiomatic.rb', line 63 def wait_for_page(timeout_in_seconds=nil) remote_control_command "waitForPageToLoad", [actual_timeout_in_milliseconds(timeout_in_seconds),] end |
#wait_for_popup(window_id, timeout_in_seconds = nil) ⇒ Object
Waits for a popup window to appear and load up.
window_id is the JavaScript window “name” of the window that will appear (not the text of the title bar) timeout_in_seconds is a timeout in seconds, after which the action will return with an error
73 74 75 76 |
# File 'lib/selenium/client/idiomatic.rb', line 73 def wait_for_popup(window_id, timeout_in_seconds=nil) remote_control_command "waitForPopUp", [window_id, actual_timeout_in_milliseconds(timeout_in_seconds) ,] end |