Selenium Chrome驱动程序无法在Windows上启动

时间:2018-06-09 06:18:13

标签: linux windows google-chrome selenium

我收到以下错误。最近两天正在挣扎,无法找出问题。

unknown error: chrome failed to start
(Driver info: chromedriver=2.40.565498 (ea082db3280dd6843ebfb08a625e3eb905c4f5ab),
platform=Windows NT 10.0.17134 x86_64) (WARNING: The server did not provide any
stacktrace information)

我的环境详情如下

  • 操作系统:Windows 10
  • Chrome驱动程序:2.40
  • Selenium:3.12.0
  • Java:1.8.172

我的代码在下面

System.setProperty("webdriver.chrome.verboseLogging", "true");                
// Check Operating System
String osName = System.getProperty("os.name");
// Set OS Related Information
String wChromeDriverPath = "C:\\MyCloud\\external\\chromedriver.exe";
String wChromePath = "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe";
String lChromeDriverPath = "/usr/bin/chromedriver";
String lChromePath = "/usr/bin/google-chrome-stable";
// Set Windows as Default
String chromeDriverPath = wChromeDriverPath;
String chromePath = wChromePath;
// Set OS Specific Chrome Driver & Chrome   
if(osName.toLowerCase().indexOf("linux") >= 0){
    chromeDriverPath = lChromeDriverPath;
    chromePath = lChromePath;
}
//Set Chrome Driver 
System.setProperty("webdriver.chrome.driver", chromeDriverPath);        
webdriver = null
if(osName.toLowerCase().indexOf("linux") >= 0){
    ChromeOptions options = new ChromeOptions();
    options.setBinary(chromePath);
    options.addArguments("--disable-dev-shm-usage");
    options.addArguments("--disable-extensions", "--headless", "--disable-gpu", "--no-sandbox");        
    webdriver = new ChromeDriver(options);
}
else{
    //No Chrome Options. Need to See the Chrome Window for testing
    webdriver = new ChromeDriver();  
}
webdriver.get("about:blank");

0 个答案:

没有答案