简体   繁体   中英

How to retrieve process ID for IE browser instance using Ruby or WATIR?

IE Browser instance is open. How do I get the process id for the Browser instance or opened tab for the browser using WATIR or Ruby:

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

here is the above tested via 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

This is however newer version than you are using, so your mileage may vary

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM