I am trying to close my Selenium session from an external Python script (not the same from where Selenium is actually running) with no success so far.
This is my Selenium sample code called test.py
:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
options = Options()
options.add_argument("-headless=new")
driver = webdriver.Chrome(options=options)
driver.get('https://www.google.com')
I would like to create another Python script saved in a file called close_Selenium.py
in where I could import the current webdriver session and close the Selenium webdriver which is running in test.py
. The code would be something like:
1. Import to close_Selenium.py
the webdriver session which is running in test.py
2. Use the driver.quit()
method to close the active window and processes that Selenium opened when executed test.py
.
Not sure if this would be possible. Another solution would be to close all the processes opened by Selenium using os.kill
but not sure how to get all the pids involved and close them all in a clean way.