Get PID of Browser launched by Selenium.


We can PID of browsers launched by Selenium webdriver. First of all, we have to create an object of the webdriver. Next, for example, to launch the browser in the Firefox browser, we have to take the help of webdriver.Firefox() class.

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.

Syntax

s = driver.service.process.pid

Example

from selenium import webdriver
#path of geckodriver.exe
driver = webdriver.Firefox(executable_path="C:\geckodriver.exe")
#launch browser
driver.get ("https://www.tutorialspoint.com/index.htm")
#obtain PID of browser
s = driver.service.process.pid
print(s)
#close browser
driver.close()

Output

Updated on: 30-Jan-2021

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements