Class | Selenium::Client::JavascriptExpressionBuilder
In: | lib/selenium/client/javascript_expression_builder.rb
Parent: | Object

### Methods

append element_value_is element_value_is_not find_element find_text find_text_in_document find_text_in_element javascript_framework_for new no_pending_ajax_requests no_pending_effects quote_escaped text_match window_script

### Attributes

script | [R] |

### Public Class methods

new(javascript_framework_name=nil)

[Source]

        # File lib/selenium/client/javascript_expression_builder.rb, line 7
     7:       def initialize(javascript_framework_name=nil)
     8:         @framework = javascript_framework_for(javascript_framework_name) if javascript_framework_name
     9:         @script = ""
    10:             end

### Public Instance methods

append(text)

[Source]

        # File lib/selenium/client/javascript_expression_builder.rb, line 12
    12:             def append(text)
    13:               @script << text
    14:               self
    15:             end

element_value_is(expected_value)

[Source]

        # File lib/selenium/client/javascript_expression_builder.rb, line 38
    38:       def element_value_is(expected_value)
    39:         append "(element != null && element.value == '#{quote_escaped(expected_value)}')"
    40:       end

element_value_is_not(expected_value)

[Source]

        # File lib/selenium/client/javascript_expression_builder.rb, line 42
    42:       def element_value_is_not(expected_value)
    43:         append "(element == null || element.value != '#{quote_escaped(expected_value)}')"
    44:       end

find_element(locator)

[Source]

        # File lib/selenium/client/javascript_expression_builder.rb, line 25
    25:       def find_element(locator)
    26:         append  "var element;\n\ntry {\nelement = selenium.browserbot.findElement('\#{quote_escaped(locator)}');\n} catch(e) {\nelement = null;\n}\n"
    27:       end

find_text(pattern, options)

[Source]

        # File lib/selenium/client/javascript_expression_builder.rb, line 46
    46:       def find_text(pattern, options)
    47:         if options[:element].nil?
    48:           find_text_in_document pattern, options
    49:         else
    50:           find_text_in_element pattern, options
    51:         end
    52:
    53:         self
    54:       end

find_text_in_document(pattern, options)

[Source]

        # File lib/selenium/client/javascript_expression_builder.rb, line 56
    56:       def find_text_in_document(pattern, options)
    57:         js_regexp = case pattern
    58:         when Regexp
    59:           pattern.inspect
    60:         else
    61:           /#{pattern}/.inspect
    62:         end
    63:         append "var text_match;\ntext_match = (null != selenium.browserbot.getCurrentWindow().document.body.innerHTML.match(\#{js_regexp}));\n"
    64:
    65:       end

find_text_in_element(pattern, options)

[Source]

        # File lib/selenium/client/javascript_expression_builder.rb, line 71
    71:       def find_text_in_element(pattern, options)
    72:         find_element(options[:element])
    73:         append "var text_match;\ntext_match = (element != null && \#{text_match(pattern)});\n"
    74:
    75:         self
    76:       end

javascript_framework_for(framework_name)

[Source]

         # File lib/selenium/client/javascript_expression_builder.rb, line 91
     91:       def javascript_framework_for(framework_name)
     92:         case framework_name.to_sym
     93:         when :prototype
     94:           JavascriptFrameworks::Prototype
     95:         when :jquery
     96:           JavascriptFrameworks::JQuery
     97:         else
     98:           raise "Unsupported Javascript Framework: #{framework_name}"
     99:         end
    100:       end

no_pending_ajax_requests()

[Source]

        # File lib/selenium/client/javascript_expression_builder.rb, line 17
    17:       def no_pending_ajax_requests
    18:         append window_script("#{@framework.ajax_request_tracker} == 0")
    19:       end

no_pending_effects()

[Source]

        # File lib/selenium/client/javascript_expression_builder.rb, line 21
    21:                         def no_pending_effects
    22:                           append window_script("Effect.Queue.size() == 0")
    23:                         end

quote_escaped(a_string)

[Source]

         # File lib/selenium/client/javascript_expression_builder.rb, line 106
    106:       def quote_escaped(a_string)
    107:         a_string.gsub(/'/, %q<\\\'>)
    108:       end

text_match(pattern)

[Source]

        # File lib/selenium/client/javascript_expression_builder.rb, line 82
    82:       def text_match(pattern)
    83:         case pattern
    84:         when Regexp
    85:           "null != element.innerHTML.match(#{pattern.inspect})"
    86:         else
    87:           "element.innerHTML == '#{quote_escaped(pattern)}'"
    88:         end
    89:       end

window_script(expression)

[Source]

         # File lib/selenium/client/javascript_expression_builder.rb, line 102
    102:       def window_script(expression)
    103:         "selenium.browserbot.getCurrentWindow().#{expression};"
    104:       end

[Validate]