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 frame, 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.
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:
Update
This has been resolved in watir-webdriver 0.3.3