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 h
from selenium import webdriver
options = webdriver.ChromeOptions()
options.add_argument("--incognito")
caps = options.to_capabilities()
browser = webdriver.Chrome(desired_capabilities=caps)
browser.get('https://amazon.in')
browser.quit()
When you use Selenium.WebDriver3.14.0 with ChromeDriver 81 bellow code should work.
ChromeOptions options = new ChromeOptions();
options.AddArgument("--incognito");
Driver = new ChromeDriver(options);
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);
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.
System.setProperty("webdriver.chrome.driver", "path for chromedriver.exe");
ChromeOptions options = new ChromeOptions();
options.addArguments("incognito");
DesiredCapabilities cap = DesiredCapabilities.chrome();
cap.setCapability(ChromeOptions.CAPABILITY, options);
driver = new ChromeDriver(cap);
driver.get("webpage URL");