2011-09-20 47 views
1

空白,我想使用的Watir-webdriver的一個select_list中返回文本選定值。下面就正常工作(例如,使用的Watir示例頁面http://bit.ly/watir-exampleselected_options收益從IFRAME

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> 

有我錯過了什麼或有另一種方式來實現這一目標?

+0

此問題存在於IE中。 FF似乎工作得很好。我目前無法檢查Chrome。 – OutKa5t

回答

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-webdriver中解決0.3.3

+0

謝謝阿利斯特。不幸的是,在我測試的代碼中,這個值並不代表文本元素,所以它對我不起作用。 「<選項值=‘2’>維修估計」 我將保持在錯誤進度表。 – OutKa5t

+1

增加了解決方法 –