Reputation: 140
package Demo;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
public class Demo {
public static void main(String[] args) {
String userProfile = "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe";
ChromeOptions options = new ChromeOptions();
options.addArguments("user-data-dir=" + userProfile);
options.addArguments("--start-maximized");
System.setProperty("webdriver.chrome.driver", "C:\\Users\\Abhishek.Dalakoti\\workspace\\HomeShopDemo\\Chromedriver.exe");
WebDriver driver = new ChromeDriver(options);
driver.get("http://www.google.com");
//driver.findElement(By.xpath("//*input[@type='text']")).sendKeys("dell");
}
}
This is the error I get when running the above. Has anyone solved this?
I've tried changing the versions of Selenium and ChromeDriver versions, but nothing worked.
Exception in thread "main" org.openqa.selenium.WebDriverException: unknown error: cannot create default profile directory
(Driver info: chromedriver=2.19.346078 (6f1f0cde889532d48ce8242342d0b84f94b114a1),platform=Windows NT 6.1 SP1 x86_64)
(WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 750 milliseconds
Build info: version: '2.52.0', revision: '4c2593c', time: '2016-02-11 19:03:33'
System info: host: 'HSNMM-AbhishekD', ip: '10.50.33.160', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_73'
Driver info: org.openqa.selenium.chrome.ChromeDriver
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:206)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:158)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:678)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:249)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:131)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:144)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:170)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:159)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:148)
at Demo.Demo.main(Demo.java:16)
Upvotes: 3
Views: 4118
Reputation: 5113
It's quite straightforward if you look at the ChromeDriver source.
If an user-data-dir
argument is passed, the application will take that to be the profile directory, and it will expect to be able to create a directory named Default
within it. If it fails to create it (and all required parents) or gets an error, you'll end up with:
cannot create default profile directory
So the solution is to ensure that what you pass to user-data-dir
exists, is a directory, is writable, and (presumably) doesn't already contain a Default
directory.
Upvotes: 2