Is it possible to get the PID of the browser that is started by Selenium Webdriver.
This would have to be in Java, as that is how I run webdriver. Is that possible?
Is it possible to get the PID of the browser that is started by Selenium Webdriver.
This would have to be in Java, as that is how I run webdriver. Is that possible?
Not particularly, you would have get the list of processes currently running and filter it down.
There is no special attributes or features that Selenium uses to launch a browser. Therefore, if you are running an instance of that browser that was launched manually, you will get that too. That is to say that if you have two instances of Firefox, one that Selenium launched and is doing it's testing on, and one of your own Firefox sessions, then you are going to have both in the filtered list, there is no way at all to tell them apart.
Take a look at this SO question. Use this code to get all currently running processes. Filter it down to the browser you are trying to get.
If you explain what you are trying to achieve by doing this, we may be able to give a better answer.
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/