java - Selenium WebDriver 无法创建 chrome 进程



所以我一直在尝试制作一个可以与网页交互以输入数据的程序。理想情况下,我想使用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运行 Administrator.so java无法启动它。

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

(适用于 Mac(更改二进制路径

/Applications/Google Chrome.app

..自:

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

最新更新