Method: Selenium::Client::Extensions#wait_for_text

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

#wait_for_text(pattern, options = {}) ⇒ Object

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.

Parameters

wait_for_text accepts an optional hash of parameters:

  • :element - a selenium locator for an element limiting the search scope.

  • :timeout_in_seconds - duration in seconds after which we time out if text cannot be found.

Regular Expressions

In addition to plain strings, wait_for_text accepts regular expressions as the pattern specification.

Examples

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"


84
85
86
87
88
# File 'lib/selenium/client/extensions.rb', line 84

def wait_for_text(pattern, options={})
  builder = JavascriptExpressionBuilder.new
  builder.find_text(pattern, options).append("text_match == true;")
  wait_for_condition builder.script, options[:timeout_in_seconds]
end