一尘不染

如何使用适用于Chrome和FireFox JAVA的webdriver禁用cookie

selenium

我想启动浏览器(FF,CHROME)以测试禁用的cookie,我尝试这样做:

           service =
                    new ChromeDriverService.Builder()
                            .usingDriverExecutable(new File("src/test/resources/chromedriver"))
                            .usingAnyFreePort().build();
            try {
                service.start();
            } catch (IOException e1) {
                e1.printStackTrace();
            }

            DesiredCapabilities capabilities = DesiredCapabilities.chrome();
            capabilities.setCapability("disable-restore-session-state", true);
            driver = new ChromeDriver(service, capabilities);

但这不行…


阅读 425

收藏
2020-06-26

共1个答案

一尘不染

我刚刚获得了Firefox的解决方案:

FirefoxProfile profile = new ProfilesIni().getProfile("default");
profile.setPreference("network.cookie.cookieBehavior", 2);
driver = new FirefoxDriver(profile);

但我不知道如何使用Chrome进行管理。

2020-06-26