Method: Selenium::Client::Idiomatic#wait_for

Defined in:
lib/selenium/client/idiomatic.rb

#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(options)
  if options[:wait_for] == :page
    wait_for_page options[:timeout_in_seconds]
  elsif options[:wait_for] == :ajax
    wait_for_ajax options
  elsif options[:wait_for] == :element
    wait_for_element options[:element], options
  elsif options[:wait_for] == :no_element
    wait_for_no_element options[:element], options
  elsif options[:wait_for] == :text
    wait_for_text options[:text], options
  elsif options[:wait_for] == :no_text
    wait_for_no_text options[:text], options
  elsif options[:wait_for] == :effects
    wait_for_effects options
  elsif options[:wait_for] == :popup
    wait_for_popup options[:window], options[:timeout_in_seconds]
    select_window options[:window] if options[:select]
  elsif options[:wait_for] == :value
    wait_for_field_value options[:element], options[:value], options
  elsif options[:wait_for] == :no_value
    wait_for_no_field_value options[:element], options[:value], options
  elsif options[:wait_for] == :visible
    wait_for_visible options[:element], options
  elsif options[:wait_for] == :not_visible
    wait_for_not_visible options[:element], options
  elsif options[:wait_for] == :condition
    wait_for_condition options[:javascript], options[:timeout_in_seconds]
  end
end