我想使用 Ruby 和 watir-webdriver 从下拉框中选择值。这是命令
browser.select_list(:id, "ctl00_SampleContent_ComboBox1_ComboBox1_OptionList").select("Whiskey")
我得到一个错误,无法找到元素,使用 {:id=>"ctl00_SampleContent_ComboBox1_ComboBox1_OptionList", :tag_name=>"select"}
有什么想法有什么问题吗?这是完整的代码:
# 1.Open http://www.asp.net/ajax/ajaxcontroltoolkit/Samples/Default.aspx
#browser = Watir::Browser.new
#browser = Watir::Browser.new :ie
profile = Selenium::WebDriver::Firefox::Profile.from_name 'WatirWebDriver'
#profile.add_extension 'autoauth-2.1-fx+fn.xpi'
browser = Watir::Browser.new :firefox, :profile => profile
browser.goto 'http://www.asp.net/ajax/ajaxcontroltoolkit/Samples/Default.aspx'
#2.Click ComboBox link on the left pane of the page
browser.a(:id, 'ctl00_SamplesLinks_ctl15_SamplesLink').click
#3.Verify that http://www.asp.net/ajax/ajaxcontroltoolkit/Samples/ComboBox/ComboBox.aspx URL opened
if browser.url.eql? "http://www.asp.net/ajax/ajaxcontroltoolkit/Samples/ComboBox/ComboBox.aspx"
puts "Error loading page \"http://www.asp.net/ajax/ajaxcontroltoolkit/Samples/ComboBox/ComboBox.aspx URL opened\""
return false
end
#4.Select “Whiskey” in the combo-box
#browser.select_list(:id, 'ctl00_SampleContent_ComboBox1_ComboBox1_OptionList').select_value('Whiskey')
puts "!!!"
browser.select_list(:id, "ctl00_SampleContent_ComboBox1_ComboBox1_OptionList").when_present.select("Whiskey")