1

I'm using windows on my system. I downloaded and extracted the chromedriver.exe file and I added it to my path.

Here is my code:

package com.chrometester.webdriver;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class chromeTest {
    public static void main(String[] args) {

        System.setProperty("webdriver.chrome.driver", "C:\\Users\\Tgagn_000\\Desktop\\selenium\\chrome");
        WebDriver driver = new ChromeDriver();
        driver.get("http://www.google.com");

    }

}

But it comes back with an error:

Exception in thread "main" java.lang.IllegalStateException: The driver executable is a directory: C:\Users\Tgagn_000\Desktop\selenium\chrome

ase
  • 13,231
  • 4
  • 34
  • 46
Taylor Gagne
  • 393
  • 2
  • 8
  • 23

4 Answers4

2
System.setProperty("webdriver.chrome.driver", 
"C:\\Users\\Tgagn_000\\Desktop\\selenium\\chrome\\chromedriver.exe");

This should fix it. You should point to the driver file, not to its directory.

Fred Porciúncula
  • 8,533
  • 3
  • 40
  • 57
  • I tried It and it worked but when it loaded the page it returned this Starting ChromeDriver 2.16.333243 (0bfa1d3575fc1044244f21ddb82bf870944ef961) on port 5393 Only local connections are allowed. – Taylor Gagne Jul 31 '15 at 14:57
  • See http://stackoverflow.com/questions/25080500/when-run-webdriver-with-chrome-browser-getting-message-only-local-connection – Fred Porciúncula Jul 31 '15 at 15:01
  • I ran it again and it run right with out any errors. Thank you for you help – Taylor Gagne Jul 31 '15 at 15:01
1

You are not adding the exe. Possibly

System.setProperty("webdriver.chrome.driver", "C:\\Users\\Tgagn_000\\Desktop\\selenium\\chrome.exe");
WebDriver driver = new ChromeDriver();
driver.get("http://www.google.com");
Saifur
  • 16,081
  • 6
  • 49
  • 73
1

As error says, you have given directory path and not .exe path.

C:\Users\Tgagn_000\Desktop\selenium\chrome\ chromedriver.exe

Use below:

System.setProperty("webdriver.chrome.driver", "C:\\Users\\Tgagn_000\\Desktop\\selenium\\chrome\\chromedriver.exe");
frianH
  • 7,295
  • 6
  • 20
  • 45
Vishal Jagtap
  • 896
  • 11
  • 16
0

You have to be careful about order of the code:

You have to write setProperty code first then initialize the ChromeDriver()

below code sequence will give you an error

WebDriver driver= new ChromeDriver();
System.setProperty("webdriver.chrome.driver", "C:\\driver\\chromedriver.exe");
driver.get("https://www.google.com/");

Below code will work

System.setProperty("webdriver.chrome.driver", "C:\\driver\\chromedriver.exe");
WebDriver driver= new ChromeDriver();
driver.get("https://www.google.com/");
Rajan Domala
  • 133
  • 1
  • 8