Selenium driver.manage().deleteAllCookies() 在使用浏览器选项时不起作用

Selenium driver.manage().deleteAllCookies() doesn't work when using Browser options

我注意到在 selenium 中使用浏览器选项时,driver.manage().deleteAllCookies() 不起作用。 不知道为什么,但这是代码片段。

var profile = new firefox.Profile('./fProfile');
profile.setPreference("browser.privatebrowsing.autostart",true);
var fOptions = new firefox.Options();
fOptions.setProfile(profile); 

var driver = new Builder()
    .withCapabilities({'browserName': 'firefox'})
    .setFirefoxOptions(fOptions)    
    .build();
driver.get("https://google.com");

在上面的驱动设置中 driver.manage().deleteAllCookies() 无效 和 driver.manage().getCookies().then((cookies)=>{console.log(cookies)}) returns 一个 数组

然而,当使用它来创建驱动程序时,上述功能有效。

driver= new Builder()
    .withCapabilities({'browserName': 'firefox'})    
    .build();

虽然我不能使用上面的代码,因为需要使用 firefox 配置文件。

平台:Node.Js 使用 geckodriver 的 Selenium

不是答案,但我会开始倒退。

您知道删除 .setFirefoxOptions(fOptions) 可以解决问题,但选项包括手动设置首选项和加载预配置的配置文件。

  • 尝试使用空白配置文件,看看会发生什么。
  • 尝试不打开隐私浏览,看看会发生什么。

你应该减少问题的根源,这样你才能得到更好的答案。

原来 关闭 隐私浏览确实 trick.Removing 线路也能正常工作。

profile.setPreference("browser.privatebrowsing.autostart",false);