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");
}
}
在执行上述操作时,我遇到了以下错误。有人解决过吗?
我尝试更改Selenium和ChromeDriver的版本,但都没有起作用。
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)