Dashboard > Watir > ... > Simple Examples > Simple Ajax examples
Watir Log In View a printable version of the current page.
Simple Ajax examples
Added by Charley Baker, last edited by Gavin Jefferies on Nov 11, 2008  (view change)
Labels: 
(None)

require 'watir'
require 'test/unit'

# Quick example of Ajax examples using Watir, should work with versions
# 1.5.1.1148 and above.

class Ajax_Example < Test::Unit::TestCase
  include Watir

  def test_scriptaculous_autocompleter
    browser = Browser.start('http://demo.script.aculo.us/ajax/autocompleter')
    browser.text_field(:id, 'contact_name').set('al')

    # need to fire a key press event after setting the text since the js is handling
    # keypress events
    browser.text_field(:id, 'contact_name').fire_event('onkeypress')   

    # the li/lis tags are available in watir 1.5.1
    wait_until {browser.div(:id, 'contact_name_auto_complete').lis.length > 0}
    puts browser.div(:id, 'contact_name_auto_complete').lis.length
    puts browser.div(:id, 'contact_name_auto_complete').li(:index, 5).text
    browser.div(:id, 'contact_name_auto_complete').li(:text, 'Alan Jochen').click
 end
end

Site running on a free Atlassian Confluence Community License granted to OpenQA. Evaluate Confluence today.
Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.5.6 Build:#812 Aug 06, 2007) - Bug/feature request - Contact Administrators