getting error with chromedriver using RemoteWebdriver

4k views Asked by At

Getting error:

FAILED CONFIGURATION: @BeforeMethod setUp org.openqa.selenium.WebDriverException: The path to the driver executable must be set by the webdriver.chrome.driver system property; for more information, see http://code.google.com/p/selenium/wiki/ChromeDriver. The latest version can be downloaded from http://chromedriver.storage.googleapis.com/index.html

My code :

capability = DesiredCapabilities.chrome();
capability.setBrowserName("chrome");
capability.setVersion("38.0.2125.122 m");
String strChromePath = System.getProperty("user.dir")
    + "\\webdrivers\\chromedriver.exe";
System.setProperty("webdriver.chrome.driver", strChromePath);
capability.setPlatform(org.openqa.selenium.Platform.ANY);
return new RemoteWebDriver(new URL("http://192.168.1.77:5555/wd/hub"),
        capability);

On the above code chromedriver it self is not getting invoked.

Then i tried with code:

ChromeDriverService chromeService = new ChromeDriverService.Builder()
            .usingDriverExecutable(new File("webdrivers/chromedriver.exe"))
            .usingAnyFreePort().build();
chromeService.start();
capability = DesiredCapabilities.chrome();
capability.setBrowserName("chrome");
capability.setVersion("38.0.2125.122 m");
capability.setPlatform(org.openqa.selenium.Platform.ANY);
return new RemoteWebDriver(new URL("http://192.168.1.77:5555/wd/hub"),
        capability);

On executing above code the executable is launched but chrome is not invoked. It throws the same error. Code is working fine for firefox. Any help please?

2

There are 2 answers

2
Subh On BEST ANSWER

Download the relevant Chrome driver as per your system(32-bit/64-bit), from here . Try setting the property of ChromeDriver first, like this:

File file = new File("D:\\chromedriver.exe"); //path to the chromedriver.exe so downloaded
System.setProperty("webdriver.chrome.driver", file.getAbsolutePath());

Then use this code:-

DesiredCapabilities capability = DesiredCapabilities.chrome();
capability.setBrowserName("chrome");
capability.setVersion("38.0.2125.122 m");
WebDriver driver = new RemoteWebDriver(new URL("http://192.168.1.77:5555/wd/hub"),capability);

If there is no need of using "RemoteWebDriver", you can code just use this below :

File file = new File("D:\\chromedriver.exe"); //path to the chromedriver.exe so downloaded
System.setProperty("webdriver.chrome.driver", file.getAbsolutePath());
WebDriver driver = new ChromeDriver();
0
Helping Hands On

Try below :

    WebDriver driver;

    System.setProperty("webdriver.chrome.driver", "properties/chromedriver.exe");

    driver = new ChromeDriver();

    driver.get("www.google.com");

Put chrome driver in properties folder.