Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make sure selenium does not close the browser?

So I was working on something that requires me to keep the browser open until unless it is closed by the user, however, the browser automatically closes after finishing its tasks, is there any way to prevent this?

def main():
    driver = webdriver.Chrome()
    driver.maximize_window()
    driver.get("https://www.google.com/")
main()
like image 881
Aamod Varma Avatar asked Nov 01 '25 15:11

Aamod Varma


1 Answers

If you want it to stay open, you have to use the 'detach' option

from selenium.webdriver.chrome.options import Options

def main():
    chrome_options = Options()
    chrome_options.add_experimental_option("detach", True)
    driver = webdriver.Chrome(chrome_options=chrome_options)
    driver.maximize_window()
    driver.get("https://www.google.com/")

This should do it

like image 167
omiguelgomes Avatar answered Nov 04 '25 07:11

omiguelgomes



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!