Java-Selenium WebDriver无法创建Chrome进程 [英] java - Selenium WebDriver failed to create chrome process

查看:142
本文介绍了Java-Selenium WebDriver无法创建Chrome进程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

So I have been trying to make a program that can interact with a webpage to input data. I ideally wanted to use Chrome so I tried to set up Selenium WebDriver and 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进程,但没有.当我终止进程时,我仍然遇到相同的错误.

I seem to have set up the external JARs correctly as I can import them with no problem. The problem is for some reason the Chrome process cannot be created. I thought this might've been because there was already a Chrome process open but no. I still got the same error when I killed the process.

然后我尝试将重置路径设置为Chrome,因为默认路径可能与我的不同,但仍然没有运气.

I then tried to set reset the path to Chrome, as the default one might've been different to mine, but still no luck.

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进程,但我似乎找不到原因.任何帮助将不胜感激(有关我的帖子格式的提示,因为这是我的第一篇帖子).谢谢

As the chromedriver seems to start fine the problem is simply in creating the chrome process but I can't seem to find out why. Any help would be appreciated(Also tips about my post formatting, as this is my first post). Thanks

推荐答案

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

I meet this problem today,and solved it finally.it's because the chrome run as Administrator.so java can't start it.

Google Chrome属性->兼容性->不以管理员身份运行

Google Chrome Properties->Compatibility->not run as administrator

这篇关于Java-Selenium WebDriver无法创建Chrome进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆