I am trying to disable all chrome extensions when starting up my selenium chrome.
But all extensions keep starting up each time I run the code.
Is there a way of disabling the extensions.
Sample Code
public static void main(String[] args) throws IOException {
System.setProperty("webdriver.chrome.driver", "C:\\Selenium\\chromedriver.exe");
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability("chrome.binary", "C:\\Users\\ngzhongqin\\AppData\\Local\\Google\\Chrome\\Application\\chrome.exe");
WebDriver driver = new ChromeDriver(capabilities);
driver.get("http://www.cnn.com");
WebElement searchBox = driver.findElement(By.name("q"));
}
Found a fix.
capabilities.setCapability("chrome.switches", Arrays.asList("--disable-extensions"));
Setting capability chrome.switches did not work for me (Chrome Version 53.0.2785.143 m, ChromeDriver 2.18.343845)
Instead using options works:
ChromeOptions options = new ChromeOptions();
options.addArguments("--disable-extensions");
driver = new ChromeDriver(options);
or as per Chrome Driver documentation to set options as capability
ChromeOptions options = new ChromeOptions();
options.addArguments("--disable-extensions");
caps.setCapability(ChromeOptions.CAPABILITY, options);
driver = new ChromeDriver(caps);
ChromeDriver(capabilities) is deprecated
Use the following to set chrome options:
ChromeOptions options = new ChromeOptions();
options.addArguments("chrome.switches","--disable-extensions");