【问题标题】:java - Selenium WebDriver failed to create chrome processjava - Selenium WebDriver 无法创建 chrome 进程
【发布时间】:2019-01-21 21:13:52
【问题描述】:

所以我一直在尝试制作一个可以与网页交互以输入数据的程序。理想情况下,我想使用 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'

由于 chromedriver 似乎启动良好,问题只是在创建 chrome 进程,但我似乎无法找出原因。任何帮助将不胜感激(还有关于我的帖子格式的提示,因为这是我的第一篇文章)。谢谢

【问题讨论】:

  • 能否指定chrome浏览器版本?
  • 是的,当然,在我写这篇文章时,我的 chrome 是最新的。版本 68.0.3440.106(64 位)。
  • 我也有同样的问题!!
  • 感谢您的链接,但似乎该线程解决了不同的问题。我的问题是我的 WebDriver 无法创建 Chrome 进程。我看过任何留下的日志,但我似乎无法理解它们。我不认为问题出在服务器上。

标签: google-chrome selenium selenium-chromedriver createprocess


【解决方案1】:

今天遇到这个问题,终于解决了,是因为chrome以Administrator身份运行,所以java无法启动。

谷歌浏览器属性->兼容性->不能以管理员身份运行

【讨论】:

  • 这绝对解决了我在 win10 上的问题
【解决方案2】:

(对于 Mac)更改二进制路径

/Applications/Google\ Chrome.app

..to:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-06-03
    • 2020-03-16
    • 1970-01-01
    • 1970-01-01
    • 2022-08-14
    • 1970-01-01
    • 1970-01-01
    • 2014-03-23
    相关资源
    最近更新 更多