I would like to get the PID of the browser launched by selenium. Is there any way to get it done?
The location of the geckodriver.exe file is passed as a parameter to that class. This is done by setting the path to executable_path property. Then, the browser shall be launched with the get method. Finally, to obtain the PID of the browser, we shall use the driver.service.process.id method.
Chrome has a built in task manager that will show you PID. You can use Shift + ESC keyboard combination to access or you could go to Options -> More Tools -> Task Manager. You may have to increase the width of the window to see it.
Using the Python API, it's pretty simple:
from selenium import webdriver browser = webdriver.Firefox() print browser.binary.process.pid # browser.binary.process is a Popen object...
If you're using Chrome, it's a little more complex, you go via a chromedriver process:
c = webdriver.Chrome() c.service.process # is a Popen instance for the chromedriver process import psutil p = psutil.Process(c.service.process.pid) print p.get_children(recursive=True)
hwjp's solution isn't working anymore for me, but the solution from ABM is working for other browsers too in case anyone is wondering, so for firefox as of now:
from selenium import webdriver driver = webdriver.Firefox() print(driver.service.process.pid)
can't comment because of reputation, so I'm submitting this as separate answer...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With