Selenium Java重用浏览器会话

时间:2016-11-28 12:35:09

标签: selenium firefox reusability

我是Java和Selenium的新手,我需要重用浏览器会话。

我已经四处寻找,但找不到一个好的解决方案。 有没有办法在Selenium中使用Java重用Firefox会话?

1 个答案:

答案 0 :(得分:0)

您有两种选择:

  1. 保存您的Cookie并在每次创建驱动程序时检索它们

    driver = new FirefoxDriver();
    for(Cookie cookie : allCookies)
    {
        driver.manage().addCookie(cookie);
    }
    
  2. 在本地保存您的浏览器配置文件,然后加载它

    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);
    
相关问题