0

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.

Claytor
  • 27
  • 7
  • No, you cannot import objects across processes. You will have to use something similar to a socket to send a signal to the other process, or even a "signal" that you trap in the other process. – Tim Roberts Apr 14 '23 at 18:08
  • Since it´s not possible to import objects across processes, I found another way to close the Selenium processes. I opened a new question giving further explanations and showing my code. Feel free to take a look to this question with a new approach: https://stackoverflow.com/questions/76018416/how-to-close-all-the-selenium-current-processes-using-an-external-python-script – Claytor Apr 14 '23 at 19:42

0 Answers0