Collect values from select_list to avoid watir-webdriver ObsoleteElementError
I am trying to work my way around the ObsoleteElementError http://bit.ly/qhEhMv and scratching my head at collecting the values from a select_list. I'm sure I have looked at it so long I'm missing something stupid. The closest I have got is
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>
<开发者_如何学JAVA/select>
<input type="submit" name="ctl00$PageContent$btnShowResult" value="" id="PageContent_btnShowResult" class="butgo" />
But this just repeats the first value until the total number of values has been reached (in this case 9).
You're looping on every option in the browser, and not using the block variable.
Try this:
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
精彩评论