Selenium WebDriver – Get Browser Hwnd

While designing some UI automation framework API, which can work with browser and other systems like window, I have to control the z order or IExplore launched by selenium web driver.


However out of box, selenium does not expose driver process id or Browser hwnd.

The attached solution with some extensions is able to get the browser hwnd..

The basic logic is

  • 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
Below is some code highlights
// Interface to extend the web driver and expose ProcessId of driver
public interface IWebDriverEx: IWebDriver
/// <summary>
/// Get the process id of driver
/// </summary>
/// <returns>process id</returns>
int ProcessId { get; }
and few extension methods
public static IntPtr GetBrowserHwnd(this IWebDriverEx driver);
public static void BringToFront(this IWebDriverEx driver);
for more details, see attached sample (download), after launch go to console and press any key to bring the browser in front…

Get Public Key Token for a Strong Named Assembly

While extending the Visual Studio development you might need to extract the public key token for a strong named assembly.

For example if you would like to use the InternalsVisibleToAttribute (Specifies that types that are ordinarily visible only within the current assembly are visible to a specified assembly) you will need to extract the Assembly’s Fully Qualified Name.


Below are the simple steps to extend the visual studio

Open Visual Studio

Go to Tools –> External Tools

Click on “Add” to add a tool, and put in the following values:

Title: Get &PublicKeyToken

Command: C:Program FilesMicrosoft SDKsWindowsv6.0ABinsn.exe

Argument: -Tp $(TargetPath)

Select the “Use output window” option

Now go to Tools>select Get PublicKeyToken option


 In most of the organizations FTP is not open and sometime client sends some documents via their FTP sites. The purpose of Web FTP is to bypass proxy and working principle is quite simple. The ASP.Net application takes user input and renders UI. The actual FTP client command execute on central web server. The documents are first download or uploaded to central web server and web application from there route it to ftp server. I find very interesting project known as Vista Web FTP on sourceforge written in ASP.Net and have hosted the tool on my web server which can be accessed at /rajnish/webftp.

 Passwords are only stored in sessions and are not logged anywhere in the application. Make sure to click on exit button when finished your ftp session, this will delete any downloaded or uploaded files on the web server (tested).

 The solution is hosted as is and only some minor changes in css (to make the fast UI) are done. (Use this at your own risk)

 Special thanks to kmanpro (author) for sharing nice tool…