在Watir中,您可以使用next方法获得IE窗口的WIN32OLE句柄。
irb(main):059:0> browser.ie
=> #<WIN32OLE:0x28d12b8>我需要得到相同的IE返回,这是由webdriver创建的。
有什么办法吗?或者至少有人能给我指明方向。
我需要这个东西来附加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)发布于 2012-04-03 14:27:15
您可以尝试使用WIN32OLE连接到正在运行的IE实例。这在Ruby上进行了讨论--参见这里。
我想你需要的代码是:
require 'win32ole'
require 'watir-webdriver'
browser = Watir::Browser.new :ie
title = browser.title
for window in WIN32OLE.new('Shell.Application').Windows
begin
if window.Document.Title == title
ie = window
end
rescue
end
end
controller = WIN32OLE.new('HttpWatch.Controller')
plugin = controller.IE.Attach(ie)我没有HttpWatch,所以我无法测试它。但是,win32ole类型似乎与Watir的browser.ie()返回的类型相同。
请注意,此解决方案假定浏览器具有唯一的标题。如果这个假设不成立,我可以写一些解决办法。
https://stackoverflow.com/questions/9980888
复制相似问题