(ZT)Simple Watir/Ajax examples

上一篇 / 下一篇  2009-07-15 23:15:19 / 个人分类:RUBY

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

TAG:

 

评分:0

我来说两句

日历

« 2024-05-03  
   1234
567891011
12131415161718
19202122232425
262728293031 

数据统计

  • 访问量: 30870
  • 日志数: 37
  • 建立时间: 2008-07-09
  • 更新时间: 2009-07-23

RSS订阅

Open Toolbar