在 Watir 中,您可以使用 next 方法获取 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:感谢 Justin Ko,我有工作代码
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)