Module | Selenium::Client::Extensions |
In: |
lib/selenium/client/extensions.rb
|
Convenience methods not explicitely part of the protocol
# File lib/selenium/client/extensions.rb, line 98 98: def active_javascript_framework(options) 99: options[:javascript_framework] || default_javascript_framework 100: end
These for all Ajax request to finish (Only works if you are using prototype, the wait in happenning browser side)
See davidvollbracht.com/2008/6/4/30-days-of-tech-day-3-waitforajax for more background.
# File lib/selenium/client/extensions.rb, line 11 11: def wait_for_ajax(options={}) 12: builder = JavascriptExpressionBuilder.new active_javascript_framework(options) 13: wait_for_condition builder.no_pending_ajax_requests.script, 14: options[:timeout_in_seconds] 15: end
Wait for all Prototype effects to be processed (the wait in happenning browser side).
Credits to github.com/brynary/webrat/tree/master
# File lib/selenium/client/extensions.rb, line 20 20: def wait_for_effects(options={}) 21: builder = JavascriptExpressionBuilder.new active_javascript_framework(options) 22: wait_for_condition builder.no_pending_effects.script, 23: options[:timeout_in_seconds] 24: end
Wait for an element to be present (the wait in happenning browser side).
# File lib/selenium/client/extensions.rb, line 27 27: def wait_for_element(locator, options={}) 28: builder = JavascriptExpressionBuilder.new 29: builder.find_element(locator).append("element != null;") 30: wait_for_condition builder.script, options[:timeout_in_seconds] 31: end
Wait for a field to get a specific value (the wait in happenning browser side).
# File lib/selenium/client/extensions.rb, line 86 86: def wait_for_field_value(locator, expected_value, options={}) 87: builder = JavascriptExpressionBuilder.new 88: builder.find_element(locator).element_value_is(expected_value) 89: wait_for_condition builder.script, options[:timeout_in_seconds] 90: end
Wait for an element to NOT be present (the wait in happenning browser side).
# File lib/selenium/client/extensions.rb, line 34 34: def wait_for_no_element(locator, options={}) 35: builder = JavascriptExpressionBuilder.new 36: builder.find_element(locator).append("element == null;") 37: wait_for_condition builder.script, options[:timeout_in_seconds] 38: end
# File lib/selenium/client/extensions.rb, line 92 92: def wait_for_no_field_value(locator, expected_value, options={}) 93: builder = JavascriptExpressionBuilder.new 94: builder.find_element(locator).element_value_is_not(expected_value) 95: wait_for_condition builder.script, options[:timeout_in_seconds] 96: end
Wait for some text to NOT be present (the wait in happenning browser side).
See wait_for_text for usage details.
# File lib/selenium/client/extensions.rb, line 79 79: def wait_for_no_text(pattern, options={}) 80: builder = JavascriptExpressionBuilder.new 81: builder.find_text(pattern, options).append("text_match == false;") 82: wait_for_condition builder.script, options[:timeout_in_seconds] 83: end
Wait for some text to be present (the wait is happening browser side).
wait_for_text will search for the given argument within the innerHTML of the current DOM. Note that this method treats a single string as a special case.
wait_for_text accepts an optional hash of parameters:
In addition to plain strings, wait_for_text accepts regular expressions as the pattern specification.
The following are equivalent, and will match "some text" anywhere within the document:
wait_for_text "some text" wait_for_text /some text/
This will match "some text" anywhere within the specified element:
wait_for_text /some text/, :element => "container"
This will match "some text" only if it exactly matches the complete innerHTML of the specified element:
wait_for_text "some text", :element => "container"
# File lib/selenium/client/extensions.rb, line 70 70: def wait_for_text(pattern, options={}) 71: builder = JavascriptExpressionBuilder.new 72: builder.find_text(pattern, options).append("text_match == true;") 73: wait_for_condition builder.script, options[:timeout_in_seconds] 74: end