从 select_list 收集值以避免 watir-webdriver ObsoleteElementError
我正在尝试解决 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)。
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>
</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).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您正在循环浏览器中的每个选项,而不是使用块变量。
试试这个:
You're looping on every option in the browser, and not using the block variable.
Try this: