[英]Selenium reusing browser session
I would like to have a single long-running browser session, that is reused between separate runs of my script. 我希望有一个长期运行的浏览器会话,可以在脚本的单独运行之间重复使用。 Thus allowing me to avoid logging in every time my script runs.
因此,我可以避免每次脚本运行时都登录。 Using other answers I have a working solution:
使用其他答案,我有一个可行的解决方案:
session_info = load_from_json()
options = webdriver.ChromeOptions()
driver = webdriver.Remote(
command_executor=session_info["executor_url"],
desired_capabilities={},
options = options)
driver.session_id = session_info["session_id"]
This has an unwanted side effect of leaving an orphaned chrome-webdriver session laying around on top of the already existing browser session. 这有一个不良的副作用,就是将一个孤立的chrome-webdriver会话放置在现有浏览器会话的顶部。 I was wondering what I can do to avoid having an extra orphaned session.
我在想如何避免发生额外的孤立会话。
Prior to loading a new session try to clear both session and local storage. 在加载新会话之前,请尝试清除会话和本地存储。
driver.getSessionStorage().clear();
driver.getLocalStorage().clear();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.