简体   繁体   English

Selenium Java重用浏览器会话

[英]Selenium Java Reuse Browser Session

I'm new to Java and Selenium and have this issue where I need to reuse the browser session. 我是Java和Selenium的新手,我需要重用浏览器会话。

I've searched around, but could not find a good solution for that. 我一直在寻找,但找不到一个好的解决方案。 Is there a way to reuse Firefox session in Selenium with Java? 有没有办法在Selenium中使用Java重用Firefox会话?

You have two options: 您有两种选择:

  1. Save your cookies and retrieve them at each creation of the driver 保存您的cookie并在每次创建驱动程序时检索它们

     driver = new FirefoxDriver(); for(Cookie cookie : allCookies) { driver.manage().addCookie(cookie); } 
  2. Save your browser profile locally and then load it 在本地保存您的浏览器配置文件然后加载它

     DesiredCapabilities capabilities = DesiredCapabilities.firefox(); File profileDirectory = new File("c://mach//lib//prof"); FirefoxProfile profile = new FirefoxProfile(profileDirectory); capabilities.setCapability(FirefoxDriver.PROFILE, profile); WebDriver driver = new FirefoxDriver(capabilities); 

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

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