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
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
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)