how to make seleniumwire.undetectedchromedriver automaticly close webdriver when i close…
- User
how to make seleniumwire.undetected_chromedriver automaticly close webdriver when i close command promt controlling it. It works with orginal selenium but undetected_chromedriver just doesn't automaticly closes so i have an opened google chrome window opened even after i close the script
- Assistant
In order to automatically close the undetected_chromedriver when closing the Command Prompt, you can use a try-except block along with the
atexitmodule to register the driver quit method to be called when the script is exited.Here's how to do it:
- First, import the necessary modules:
import atexit from seleniumwire import undetected_chromedriver as uc- Next, create a driver instance:
options = uc.ChromeOptions() options.headless = False driver = uc.Chrome(options=options)- Make sure to register the
driver.quitmethod to be called when the script is exited:
# Register the close method to run when the script is exited atexit.register(driver.quit)- Then, your script will continue, and the driver will be closed when the Command Prompt is closed: