Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selenium python web driver doesnt close

I call driver.quit() on test teardown, but the chromedriver process stays alive and doesn't shut down. So between executions sometimes Chrome doesn't open at all, and I need to manually shut down the processes. Someone familiar with this issue?

I'm using selenium 3.5

like image 688
Alon Dayan Avatar asked Sep 28 '17 07:09

Alon Dayan


People also ask

How do I close Selenium window Python?

close() closes only the current window on which Selenium is running automated tests. The WebDriver session, however, remains active. On the other hand, the driver. quit() method closes all browser windows and ends the WebDriver session.

How do I close Web drivers?

close() The close() method is a Webdriver command that closes the browser window currently in focus. It is best to use the close() command when multiple browser tabs or windows are open. If only one window is open in the entire browser, then the close() command will quit the entire browser session.

How do you close a browser in Python?

close() method is used to close the current browser window on which the focus is set, on the other hand quit() method essentially calls the driver.

What is the difference between quit () and close () method in Selenium?

The difference between quit() and close() driver. quit() : The quit() method quits the driver, closing every associated window. driver. close() : The close() method closes the currently focused window, quitting the driver if the current window is the only open window.


1 Answers

Change your code to below, to be double sure the process is not there after quit

import signal
import os
pid = driver.service.process.pid

driver.quit()
try:
    os.kill(int(pid), signal.SIGTERM)
    print("Killed chrome using process")
except ProcessLookupError as ex:
    pass
like image 188
Tarun Lalwani Avatar answered Oct 02 '22 19:10

Tarun Lalwani