Get Window handle (IntPtr) from Selenium webdriver's current window GUID

后端 未结 3 1630
野趣味
野趣味 2021-01-17 17:43

I\'m trying to capture a screenshot of whole browser screen (e.g. with any toolbars, panels and so on) not only an entire page, so I\'m got this code:

using          


        
3条回答
  •  终归单人心
    2021-01-17 18:27

    Out of box, selenium does not expose driver process id or Browser hwnd but it is possible. Below is the logic to get hwnd

    • When driver is initialized, get the url for hub and extract the port number
    • From port number, find the process id which is using this port for listening, ie. PID of driver
    • After navigation, from all instances of iexplore find the parent PID matches the pid of driver, i.e browser pid.
    • Get the Hwnd of browser pid once browser hwnd is found , you can use win32 api to bring selenium to foreground.

    its not possible to post full code here, the full working solution (C#) to bring browser in front is on my blog

    http://www.pixytech.com/rajnish/2016/09/selenium-webdriver-get-browser-hwnd/

提交回复
热议问题