ChromeDriver cannot find Chrome binary问题解决

1、运行程序

 @Test
 public void testChrome() throws InterruptedException {
   System.setProperty("webdriver.chrome.driver","D:\\codeware\\eclipse\\eclipse_neon_workspace\\selenium\\resources\\chromedriver.exe");
   WebDriver dr = new ChromeDriver();
   dr.manage().window().maximize();
         dr.get("http://localhost:8080/jenkins/");
         Thread.sleep(2000);
     //  dr.manage().window().maximize();
         dr.findElement(By.id("j_username")).sendKeys("admin");
         dr.findElement(By.name("j_password")).sendKeys("352cba3875a2446abd5935b1a60d726f");
         dr.findElement(By.id("yui-gen1-button")).click();
  
 
 }


2、出现的问题

Starting ChromeDriver (v2.4.226107) on port 9496
Exception in thread "main" org.openqa.selenium.WebDriverException: unknown error: cannot find Chrome binary
  (Driver info: chromedriver=2.4.226107,platform=Windows NT 6.1 SP1 x86_64) (WARNING: The server did not provide any stacktrace information)



3、解决

添加:

  ChromeOptions options = new ChromeOptions();
   options.setBinary("C:/Program Files (x86)/Google/Chrome/chrome.exe");
   WebDriver dr = new ChromeDriver(options);


@Test
 public void testChrome() throws InterruptedException {
   System.setProperty("webdriver.chrome.driver","D:\\codeware\\eclipse\\eclipse_neon_workspace\\selenium\\resources\\chromedriver.exe");
   ChromeOptions options = new ChromeOptions();
   options.setBinary("C:/Program Files (x86)/Google/Chrome/chrome.exe");
   WebDriver dr = new ChromeDriver(options);
   dr.manage().window().maximize();
         dr.get("http://localhost:8080/jenkins/");
         Thread.sleep(2000);
     //  dr.manage().window().maximize();
         dr.findElement(By.id("j_username")).sendKeys("admin");
         dr.findElement(By.name("j_password")).sendKeys("352cba3875a2446abd5935b1a60d726f");
         dr.findElement(By.id("yui-gen1-button")).click();
  
 
 }


之后就能运行了


  • 3
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值