简体   繁体   中英

local connection issue selenium web driver with chrome driver

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)

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM