Module: WatirJquery

Included in:
Watir::Browser
Defined in:
lib/watir-jquery.rb,
lib/watir-jquery/version.rb

Constant Summary collapse

PATH_TO_JQUERY =
'http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js'
VERSION =
"0.0.2"

Instance Method Summary collapse

Instance Method Details

#jquery(selector) ⇒ Object Also known as: jq



6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/watir-jquery.rb', line 6

def jquery(selector)
  define_jquery unless jquery_defined?

  script = "var a=jQuery('#{selector}'); var b=[];for(var i =0; i< a.length; i++){b[i] = a[i]}return b;"
  elements = browser.execute_script(script)
  return elements[0] unless elements.count > 1

  # This would be nice, but can't figure out how to instantiate
  # see watir-webdriver/element_collection.rb
  # Watir::DivCollection.new(elements)

  elements
end