通过selenium在firefox中打开私有模式

其实我想通过selenium打开一个隐身/私有模式的firefox浏览器,但每次我试过它都是在正常模式下打开firefox。

经过一些谷歌搜索我得到了这个代码,我曾经通过selenium在firefox中打开私有模式,但它无法正常工作。

FirefoxProfile firefoxProfile = new FirefoxProfile(); firefoxProfile.setPreference("browser.privatebrowsing.autostart", true); WebDriver driver = new FirefoxDriver(firefoxProfile); driver.get("http://www.google.com"); 

有人可以帮忙怎么做?