1

watir-webdriverを使用してselect_listから選択した値のテキストを返そうとしています。以下は通常は機能します(Watirサンプルページhttp://bit.ly/watir-exampleを使用した例)

browser = Watir::Browser.new :ie
browser.goto "http://bit.ly/watir-example"
browser.select_list(:id => "entry_6").option(:index, 2).select
puts browser.select_list(:id => "entry_6").select_list(:id => "entry_6").selected_options

=>Internet Explorer

しかし、同じコードをフレームに貼り付けても、何も返されません。

browser = Watir::Browser.new :ie
browser.goto "test_iframe.html"
browser.frame(:id => "test").select_list(:id => "entry_6").option(:index, 2).select
puts browser.frame(:id => "test").select_list(:id => "entry_6").select_list(:id => "entry_6").selected_options

=>Nothing returned

iframeの例:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>

<body>
<p>TEST IFRAME ISSUES</p>

<iframe src="http://bit.ly/watir-example" id="test" width="100%" height="1400px">

</iframe>

</body>
</html>

私は何かを逃したことがありますか、それともこれを達成する別の方法がありますか?

4

1 に答える 1

1

select_listがWindowsのiFrameにある場合、selected_optionsのバグのように見えます。代わりに.valueを使用してみてください。

b = Watir::Browser.start 'http://dl.dropbox.com/u/18859962/iframe.html', :ie
b.frame.exist? #=> true
b.frame.text_fields.count #=> 2
b.frame(:id => "test").select_list(:id => "entry_6").option(:index, 2).select
puts b.frame(:id => "test").select_list(:id => "entry_6").selected_options #=> nil
puts b.frame(:id => "test").select_list(:id => "entry_6").value
 # Internet Explorer
b.goto "bit.ly/watir-example"
b.select_list(:id => "entry_6").option(:index, 2).select
puts b.select_list(:id => "entry_6").selected_options #Internet Explorer
puts b.select_list(:id => "entry_6").value #Internet Explorer

私はこれをWatir-WebDriverのバグとして提起しました:https ://github.com/jarib/watir-webdriver/issues/102

アップデート

それまでの間、オプションをループして、選択したオプションを見つけて、htmlテキストを吐き出すことができます。

require 'nokogiri'
b.frame(:id => "test").select_list(:id => "entry_6").options.each do |option|
  puts Nokogiri::HTML(option.html).text if option.selected?
end

アップデート

これはwatir-webdriver0.3.3で解決されました

于 2011-09-20T23:41:15.130 に答える