Why is my Selenium browser closing itself in Python

Viewed 30

When I run the file it closes itself automatically without driver.close()


driver = webdriver.Chrome()
driver.get("https://www.roblox.com/login")
searchbox = driver.find_element("xpath",'//*[@id="login-username"]')
searchbox.send_keys("ade")
passwordsearch = driver.find_element("xpath",'//*[@id="login-password"]')
passwordsearch.send_keys("abcde")

1 Answers

You have to add ChromeOptions() with 'detach' option to prevent the browser window closing automatically.

options = Options()
options.add_experimental_option('detach', True)
driver = webdriver.Chrome(service=ChromeService(ChromeDriverManager().install()), options = options)
Related