1
在Watir中,您可以使用下一個方法獲得IE窗口的WIN32OLE句柄。如何通過watir-webdriver爲IE獲取WIN32OLE句柄?
irb(main):059:0> browser.ie
=> #<WIN32OLE:0x28d12b8>
我需要以某種方式獲得由watir-webdriver創建的IE的相同返回。
有什麼方法嗎?或者至少有人能指出我要挖掘的方向。
我需要這個東西來將HTTPwatch插件附加到我的瀏覽器實例。這裏是HTTPWatch代碼的例子。
require 'watir'
require 'win32ole'
browser = Watir::Browser.new
controller = WIN32OLE.new('HttpWatch.Controller')
plugin = controller.IE.Attach(browser.ie)
UPD:由於官高我有工作代碼
require 'win32ole'
require 'watir-webdriver'
browser = Watir::Browser.new :ie
title = browser.title
browser.goto "google.com"
length = WIN32OLE.new('Shell.Application').Windows.count - 1
(0..length).each do |i|
begin
WIN32OLE.new('Shell.Application').Windows(i).Document.Title
$ie = WIN32OLE.new('Shell.Application').Windows(i)
rescue
end
end
controller = WIN32OLE.new('HttpWatch.Controller')
plugin = controller.IE.Attach($ie)
嗨,非常感謝您的幫助。你的代碼不起作用,但有點改變的版本很好。這是 '需要 'WIN32OLE' 需要 '的Watir-webdriver的' 瀏覽器=的Watir :: Browser.new:即 標題= browser.title browser.goto 「google.com」 長度= WIN32OLE.new ('Shell.Application')。Windows.count - 1 (0..length).each do | i | \t開始 提出WIN32OLE.new( 'Shell.Application')。視窗(I).Document.Title 把$即= WIN32OLE.new( 'Shell.Application')。視窗(I) 救援 結束 結束 controller = WIN32OLE.new('HttpWatch.Controller') plugin = controller.IE.Attach($ ie)' – 2012-04-05 13:59:09