如何使用Ruby或WATIR检索IE浏览器实例的进程ID?

时间:2015-03-02 12:14:10

标签: ruby internet-explorer watir browser-automation watir-classic

IE浏览器实例已打开。如何使用WATIR或Ruby获取浏览器实例的进程ID或浏览器的打开选项卡:

require "Watir"
browser = Watir::Browser.new
browser.goto "www.google.com"
puts Watir::Browser::Process.process_id_from_hwnd browser.hwnd

1 个答案:

答案 0 :(得分:1)

require 'watir-classic'
browser = Watir::Browser.new
Watir::Browser::Process.process_id_from_hwnd browser.hwnd

这是上面通过IRB测试的

C:\Users\Chuck>irb
irb(main):001:0> require 'watir-classic'
=> true
irb(main):002:0> browser = Watir::Browser.new
=> #<Watir::Browser:0x22f00454 url="about:blank" title="">
irb(main):003:0> Watir::Browser::Process.process_id_from_hwnd browser.hwnd
=> 3752

然而,这是比您使用的更新的版本,因此您的里程可能会有所不同

C:\Users\Chuck>gem list watir

*** LOCAL GEMS ***

commonwatir (4.0.0)
watir (5.0.0 x86-mingw32)
watir-classic (4.0.1)
watir-webdriver (0.6.11)