我注意到在 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)})
返回一个空数组
但是,当使用它来创建驱动程序时,上述功能可以工作。
driver= new Builder()
.withCapabilities({'browserName': 'firefox'})
.build();
虽然我不能使用上面的代码,因为我需要使用 Firefox 配置文件。
平台:Node.Js Selenium 使用 geckodriver
原来关闭隐私浏览就成功了。删除线路也有效。
profile.setPreference("browser.privatebrowsing.autostart",false);
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句