Selenium 2 Chrome Switches via ChromeDriver


Ok, I’m loving the combination of Selenium 2 with Twist.  This is especially true when using the new WebDriver implementation from the Chromium team.  It’s blisteringly fast, and is helping shorten the CI feedback loop even more (very important to our teams!).  Thanks to everyone involved in delivering this to the world.  However, one thing stumped me when working with the new chromedriver.exe set up… How do I pass command line switches on to Chrome browser instance being launched?  I worked it out from looking in the Chromium source for tests (always a good place to start for gaining an understanding).  Here is the solution below (expanding on some code from one of my previous posts in my WebDriverFactory).

WebDriverEventListener eventListener = new LoggingWebDriverEventListener();

service = new ChromeDriverService.Builder()
.usingChromeDriverExecutable(new File("./libs/chromedriver_win32_13.0.775.0/chromedriver.exe"))

DesiredCapabilities capabilities =;
String[] switches = {"start-maximized","remote-debugging-port=9222"};
capabilities.setCapability("chrome.switches", switches);

selenium = new EventFiringWebDriver(new RemoteWebDriver(service.getUrl(), capabilities)).register(eventListener);

It’s not doing anything exciting I know, but I thought this post might help out anyone else who might be struggling with finding the way to achieve the same thing.

I seriously want to work out a way of hooking nicely in to the remote debugger interface over Web Inspector Protocol next.  This little gem was the first step for integrating my efforts with Selenium 2, and therefore it’s of value to me (and as a by product… may be to you).  Any way, on with working out how to handle web sockets to get this WIP integration idea of mine some legs.

One Reply to “Selenium 2 Chrome Switches via ChromeDriver”

Leave a Reply