注销时,通过任务计划程序运行Selenium ChromeDriver脚本

时间:2018-01-12 21:30:48

标签: java selenium-webdriver scheduled-tasks selenium-chromedriver

前言,我无法在--headless模式下运行,因为我很遗憾需要下载文件,而使用不带--headless的ChromeDriver是我可以使用它的唯一方法。该脚本可以手动运行,并且在计划和登录时也可以正常运行,但在计划和屏幕锁定/用户注销时失败。

理想情况下,我希望能够在注销时运行,但仍然可以访问我登录/解锁时存在的默认ChromeDriver行为。我有一种不好的感觉,这是不可能的,因为好像非无头版本似乎取决于图形输入,但我希望我错了。同样,文件下载是这里的主要约束,否则我只会使用HTMLUnitDriver

以下是我的驱动程序配置供参考:

    //browser prefs
    HashMap<String, Object> preferences = new HashMap<>();
    preferences.put("profile.default_content_settings.popups", 0);
    preferences.put("download.default_directory", downloadPath);

    //browser options config
    ChromeOptions options = new ChromeOptions();
    options.setExperimentalOption("prefs", preferences);

    DesiredCapabilities cap = DesiredCapabilities.chrome();
    cap.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
    cap.setCapability(ChromeOptions.CAPABILITY, options);

    //add capabilities to options
    options.merge(cap);

    WebDriver driver = new ChromeDriver(options);

我使用的是最新版本的chromedriver.exe

1 个答案:

答案 0 :(得分:0)

我认为,重点是,当你没有登录Windows时,你试图运行测试。 也许你应该为自动测试创建服务器。稳定且无成本将是Linux上的服务器。你可以在没有x翼的情况下发射 -  更多(如果对于Firefox,你可以将驱动程序更改为chromedriver,一切都会正常工作)Is it possible to run selenium (Firefox) web driver without a GUI?