开发者

selected_options returns blank from iframe

I am trying to return the text for selected value from a select_list using watir-webdriver. The following would normally work (example using the Watir example page 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

But, if you stick the same code against a fram开发者_如何学Pythone, I get nothing back.

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 example:

<!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>

Have I missed something or is there another way to achieve this?


Looks like a bug in selected_options when the select_list is in an iFrame on Windows. Try using .value instead.

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

I have raised this as a Watir-WebDriver bug: https://github.com/jarib/watir-webdriver/issues/102

Update

In the meantime, you can loop through the options, find the selected one, and then spit out the html text:

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

Update

This has been resolved in watir-webdriver 0.3.3

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜