java - Selenium WebDriver 无法创建 chrome 进程

java - Selenium WebDriver failed to create chrome process

所以我一直在尝试制作一个可以与网页交互输入数据的程序。我理想情况下想使用 Chrome 所以我尝试设置 Selenium WebDriver 和 ChromeDriver.

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;

public class Chrome {

public static void main(String[] args) {

    //Set chromedriver path
    System.setProperty("webdriver.chrome.driver","C:/Users/Username/Desktop/Comp Sci work/chromedriver.exe");

    WebDriver driver = new ChromeDriver();

     // Open Google
    driver.get("http://www.google.com");

    // Maximize browser
    driver.manage().window().maximize();

}
}

我似乎已经正确设置了外部 JAR,因为我可以毫无问题地导入它们。问题是由于某种原因无法创建 Chrome 进程。我认为这可能是因为已经有一个 Chrome 进程打开但没有。当我终止进程时,我仍然遇到同样的错误。

然后我尝试将路径重置为 Chrome,因为默认路径可能与我的不同,但仍然没有成功。

public class Chrome {

public static void main(String[] args) {

    //Set chromedriver path
    System.setProperty("webdriver.chrome.driver","C:/Users/Username/Desktop/Comp Sci work/chromedriver.exe");

    ChromeOptions options = new ChromeOptions();
    options.setBinary("C:\Users\Username\AppData\Local\Google\Chrome\Application\chrome.exe");

    WebDriver driver = new ChromeDriver();

     // Open Google
    driver.get("http://www.google.com");

    // Maximize browser
    driver.manage().window().maximize();

}
}

错误信息是:

Starting ChromeDriver 2.41.578737 (49da6702b16031c40d63e5618de03a32ff6c197e) 
on port 43997
Only local connections are allowed.
Exception in thread "main" org.openqa.selenium.WebDriverException: unknown 
error: Failed to create a Chrome process.
(Driver info: chromedriver=2.41.578737 
(49da6702b16031c40d63e5618de03a32ff6c197e),platform=Windows NT 10.0.17134 
x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 199 milliseconds
Build info: version: '3.14.0', revision: 'aacccce0', time: '2018-08- 
02T20:05:20.749Z'

由于 chrome 驱动程序似乎可以正常启动,所以问题出在创建 chrome 进程中,但我似乎无法找出原因。任何帮助将不胜感激(还有关于我的 post 格式的提示,因为这是我的第一个 post)。谢谢

今天遇到这个问题,解决了finally.it是因为chrome运行和Administrator.sojava无法启动。

Google Chrome 属性->兼容性->不是 运行 作为管理员

(for Mac) 从

更改二进制路径
/Applications/Google\ Chrome.app

..至:

/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome