我正试图绕过ObsoleteElementError http://bit.ly/qhEhMv并试图从select_list中收集值。我确定我已经看了很长时间,我错过了一些愚蠢的东西。我最接近的是
SearchPeriodList = browser.select_list(:name => "ctl00$PageContent$ddlPeriodSelector")
SearchPeriodValues = browser.options.collect { |item| SearchPeriodList.option.value }
SearchPeriodValues.each do |item|
puts "Selected Period: #{item}"
browser.select_list.option(:value => (item)).select
browser.button(:id => "PageContent_btnShowResult").click
end
<select name="ctl00$PageContent$ddlPeriodSelector" id="PageContent_ddlPeriodSelector">
<option value="42">2011 Jun-Jul</option>
<option value="41">2011 Apr-May</option>
<option value="40">2010 Dec-Mar 2011</option>
<option value="39">2010 Sep-Nov</option>
<option value="33">2010 Jul-Aug</option>
<option value="26">2010 May-Jun</option>
<option value="18">2010 Mar-Apr</option>
<option value="19">2009 Aug</option>
<option value="29">2009 Apr</option>
</select>
<input type="submit" name="ctl00$PageContent$btnShowResult" value="" id="PageContent_btnShowResult" class="butgo" />
但这只是重复第一个值,直到达到总值数(在本例中为9)。
答案 0 :(得分:1)
您循环浏览器中的每个选项,而不是使用块变量。
试试这个:
require 'watir-webdriver'
b = Watir::Browser.new
b.goto 'http://dl.dropbox.com/u/18859962/outka5t.html'
search_period_list = b.select_list :name => 'ctl00$PageContent$ddlPeriodSelector'
search_period_values = search_period_list.options.collect { |option| option.value }
# => ["42", "41", "40", "39", "33", "26", "18", "19", "29"]
search_period_values.each do |item|
puts item
b.select_list(:name => 'ctl00$PageContent$ddlPeriodSelector').option(:value => (item)).select
b.button(:id => "PageContent_btnShowResult").click
end