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
{
/// <summary>
/// Get the process id of driver
/// </summary>
/// <returns>process id</returns>
int ProcessId { get; }
}