I want to run chrome in incongito
mode through selenium.
I googled enough for it and found how to run chrome directly in incongito
mode with the help of this link:
- Right click on the shortcut of Google Chrome and select "Properties".
- On "Shortcut" tab on the "Target" field add an –incognito to the end of program path. So in the "Target" field you should have
"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" –incognito
but I didn't get how to run this in selenium.
kailash gaur
One other way to launch chrome in incognito mode is to add argument "-incognito" like following:
ChromeOptions options = new ChromeOptions();
options.addArguments("--incognito");
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
This solution works for me.
According to the ChromeDriver wiki you can pass parameters to the executable like this:
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability("chrome.switches", Arrays.asList("--incognito"));
WebDriver driver = new ChromeDriver(capabilities);
So passing the paremeter --incognito should do the trick.
Maharshi Adiraju
The code below will open the browser in incognito mode using selinium. Assuming selenium is setup in your eclipse:
public WebDriver chromedriver;
ChromeOptions options = new ChromeOptions();
options.addArguments("--incognito");
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
WebDriver chromedriver=new ChromeDriver(capabilities);
来源:https://stackoverflow.com/questions/19026295/run-chrome-browser-in-inconginto-mode-in-selenium