现在我有这样的代码:
require "watir-webdriver"
browser = Watir::Browser.new :ff
browser.driver.manage.timeouts.implicit_wait = 3 #3 seconds
browser.goto "https://page***/default.aspx"
browser.select_list(:name => 'ctl00$tresc$cbListaKrajow').select_value('6')
puts "Selected country"
browser.select_list(:name => 'ctl00$tresc$cbListaPlacowek').wait_until_present
browser.select_list(:name => 'ctl00$tresc$cbListaPlacowek').select_value('95')
puts "Selected city"
但主要的麻烦是ctl00$tresc$cbListaPlacowek
仅通过
ctl00$tresc$cbListaKrajow is changed. It could take 1 or 30 seconds so `browser.driver.manage.timeouts.implicit_wait = 3 #3 seconds` is not a good idea. How can i write that it try to select option unless it is present? Now i get errors like it could find such option...
答案 0 :(得分:2)
请注意,您也可以这样做:
browser.select_list(:name => 'ctl00$tresc$cbListaPlacowek').option(:value => '95').wait_until_present
写一点好看。
<强>更新强>
如果您想等待任何选项出现在选择列表中,您可以这样做:
browser.select_list(:name => 'ctl00$tresc$cbListaPlacowek').option.wait_until_present
这在技术上等待出现第一个选项。请注意,根据您的操作,这可能会给您带来误报。例如,如果选择列表已填充了选项,则会触发某个事件以重新填充列表,选择列表将具有第一个选项。在这种情况下,您可能还必须检查选项列表是否已更改。
如果要选择一个值与数组中的任何值匹配的选项,您可以执行以下操作:
browser.select_list(:name => 'ctl00$tresc$cbListaPlacowek').options.find do |option|
somearray.include?(option.value)
end.select
答案 1 :(得分:1)
由我自己创立:
Watir::Wait.while { browser.select_list(:name => 'ctl00$tresc$cbListaPlacowek').include?('95') }