简体   繁体   English

为什么我的 Selenium 浏览器在 Python 中自行关闭

[英]Why is my Selenium browser closing itself in Python

When I run the file it closes itself automatically without driver.close()当我运行文件时它会自动关闭而不需要 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")

You have to add ChromeOptions() with 'detach' option to prevent the browser window closing automatically.您必须添加带有“分离”选项的ChromeOptions() ,以防止浏览器 window 自动关闭。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM