它會在一個新窗口中打開,並顯示默認的開始菜單,並顯示Chrome正在通過自動化測試軟件控制的通知,但它不會轉到網址。Selenium ChromeDriver不會使用默認用戶數據訪問網址
System.setProperty("webdriver.chrome.driver","C:\\Users\\"+System.getProperty("user.name")+"\\chromedriver.exe");
ChromeOptions options = new ChromeOptions();
options.setBinary("C:\\Users\\"+System.getProperty("user.name")+"\\AppData\\Local\\Google\\Chrome\\Application\\chrome.exe");
options.addArguments("--user-data-dir=C:\\Users\\"+System.getProperty("user.name")+"\\AppData\\Local\\Google\\Chrome\\User Data\\");
WebDriver driver = new ChromeDriver(options);
driver.get("https://www.google.com");
我也試過:
System.setProperty("webdriver.chrome.driver","C:\\Users\\"+System.getProperty("user.name")+"\\chromedriver.exe");
ChromeOptions options = new ChromeOptions();
options.setBinary("C:\\Users\\"+System.getProperty("user.name")+"\\AppData\\Local\\Google\\Chrome\\Application\\chrome.exe");
options.addArguments("--user-data-dir=C:\\Users\\"+System.getProperty("user.name")+"\\AppData\\Local\\Google\\Chrome\\User Data\\");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
WebDriver driver = new ChromeDriver(capabilities);
driver.get("https://www.google.com");
例外它給
Exception in thread "main" org.openqa.selenium.WebDriverException: unknown error: Chrome failed to start: crashed (Driver info: chromedriver=2.30.477700 (0057494ad8732195794a7b32078424f92a5fce41),platform=Windows NT 10.0.14393 x86_64) (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 61.65 seconds
我使用的是最新的ChromeDriver 2.30和硒3.4.0版本
是您的谷歌瀏覽器58之間的版本 - 60? – Renato
@renato是的,它是59 – coder35
[Selenium Docker鏡像](https://github.com/SeleniumHQ/docker-selenium/blob/master/NodeChrome)設置爲「Chrome 53」和「ChromeDriver 2.30」。你可以嘗試版本'53'看看它是否有幫助嗎? – Tom