I have cookies with Gmail login info, so that chrome automatically opens my Gmail.
I tried the following code, but it didn't work:
System.setProperty("webdriver.chrome.driver","chromedriver\\chromedriver.exe");
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability("chrome.switches", Arrays.asList("C:\\Users\\Owner\\AppData\\Local\\Google\\Chrome\\User Data\\Default"));
//I also tried using: capabilities.setCapability("chrome.switches", Arrays.asList("--user-data-dir = C:\\Users\\Owner\\AppData\\Local\\Google\\Chrome\\User Data\\Default"));
WebDriver driver = new ChromeDriver(capabilities);
driver.get("https://gmail.com");
I checked the directory of C:\\Users\\Owner\\AppData\\Local\\Google\\Chrome\\User Data\\Default
it is okay.
What is the problem in here?
There is a Known issues section on the Chrome Driver official wiki page I haven't noticed before:
Known Issues
3 . Cannot specify a custom profile
Now, I don't know whether this is or isn't outdated. I could not find a bug report for this. It's true that you can't specify a custom profile via Capabilities
(as of July 2013), as you discovered. But there is a solution...
Here's how I managed to make it run:
ChromeOptions opt = new ChromeOptions();
opt.setBinary("E:\\some\\path\\chrome.exe");
opt.addArguments("--user-data-dir=C:\\Users\\Owner\\AppData\\Local\\Google\\Chrome\\User Data");
driver = new ChromeDriver(opt);
Notice the path to the User data directory - it does not have the \\Default
part. And in that case, it works just fine for me, opens up the Chrome profile stored with all the cookies and logins.
I have no idea why the Capabilities
solution does not work. It might be worthwile to file a bug as I could not find one on topic.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With