0
votes

I want to setup the selenium with netbeans and got an error. If any one help me, its good for me. Code:

package testfirst;

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

/**
 *
 * @author haseeb.saleem
 */
public class Testfirst {

    /**
     * @param args the command line arguments
     */
    private static WebDriver driver = null;
    public static void main(String[] args) {
        // TODO code application logic here
        System.setProperty("WebDriver.chrome.driver", "C:\\Users\\haseeb.saleem\\Desktop\\chromedriver.exe");
        driver = new ChromeDriver();
        driver.get("https:\\google.com.pk");


    }

}

Error

Exception in thread "main" java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.chrome.driver system property; for more information, see https://github.com/SeleniumHQ/selenium/wiki/ChromeDriver. The latest version can be downloaded from http://chromedriver.storage.googleapis.com/index.html at com.google.common.base.Preconditions.checkState(Preconditions.java:754) at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:124) at org.openqa.selenium.chrome.ChromeDriverService.access$000(ChromeDriverService.java:32) at org.openqa.selenium.chrome.ChromeDriverService$Builder.findDefaultExecutable(ChromeDriverService.java:137) at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:329) at org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:88) at org.openqa.selenium.chrome.ChromeDriver.(ChromeDriver.java:123) at testfirst.Testfirst.main(Testfirst.java:24) C:\Users\haseeb.saleem\AppData\Local\NetBeans\Cache\8.2\executor-snippets\run.xml:53: Java returned: 1 BUILD FAILED (total time: 1 second)

2

2 Answers

1
votes

As stated in the exception, the name of the system property is: webdriver.chrome.driver and not WebDriver.chrome.driver. Please make changes accordingly.

0
votes

It is syntax error in setproperty() method, the correct code is :

private static WebDriver driver = null;
    public static void main(String[] args) {
        // TODO code application logic here
        System.setProperty("webdriver.chrome.driver", "C:\\Users\\haseeb.saleem\\Desktop\\chromedriver.exe");
        driver = new ChromeDriver();
        driver.get("https:\\google.com.pk");

}

Also it is good to use single forward slash

System.setProperty("webdriver.chrome.driver", "C:/Users/haseeb.saleem/Desktop/chromedriver.exe")