How to prevent undetected chromedriver from closing window after last line of code

Viewed 1463

I am using the undetected chromedriver in python selenium, my problem is that it always closes the window after ending the program.

For example I have a line of code like:

driver.get('www.google.com')

It obviously opens google but then immediately closes the window. When I use my own chromedriver, the window stays open and I can still surf on that window even when the program ends.

Any solutions?

2 Answers

I simply add a time.sleep(100) function, or kill the kernel

This is because the undetected chromedriver destructor terminates the chrome process when the class is destroyed.

Then you can extend the class and override the __del__ method

import undetected_chromedriver.v2 as uc

class My_Chrome(uc.Chrome):
    def __del__(self):
        pass

driver = My_Chrome()
driver.get('www.google.com')
Related