selected_options 从 iframe 返回空白
我正在尝试使用 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>
我是否错过了某些内容或者是否有其他方法可以实现此目的?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当 select_list 位于 Windows 上的 iFrame 中时,看起来像是 selected_options 中的错误。尝试使用 .value 代替。
我已将其作为 Watir-WebDriver 错误提出: https://github.com/jarib/ watir-webdriver/issues/102
Update
同时,您可以循环浏览选项,找到选定的选项,然后吐出 html 文本:
Update >
这有已在 watir-webdriver 0.3.3 中解决
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