selected_options 从 iframe 返回空白

发布于 2024-12-05 19:15:41 字数 1211 浏览 1 评论 0原文

我正在尝试使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

凝望流年 2024-12-12 19:15:41

当 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

Update

同时,您可以循环浏览选项,找到选定的选项,然后吐出 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

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.

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文