¿Por qué no he podido conjunto de propiedades del sistema para mi WebDriver selenio (Java)?

Steve:
public class Main {

    static Locators Locators = new Locators();
    static WebDriver driver = new ChromeDriver();

    public static void main(String[] args) {

        System.setProperty("webdriver.chrome.driver", "C:\\Users\\currentuser\\chromedriver.exe");
        ...
    }

me estoy poniendo la siguiente excepción:

Exception in thread "main" java.lang.ExceptionInInitializerError
Caused by: 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:847)
    at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:134)
    at org.openqa.selenium.chrome.ChromeDriverService.access$000(ChromeDriverService.java:35)
    at org.openqa.selenium.chrome.ChromeDriverService$Builder.findDefaultExecutable(ChromeDriverService.java:159)
    at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:355)
    at org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:94)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:123)
    at Main.<clinit>(Main.java:11)

en esta línea:

static WebDriver driver = new ChromeDriver();

¿Por qué recibo este aunque incluya he definido sys.setproperty y cómo puedo solucionarlo dentro de mi código?

supputuri:

Como se ha mencionado @Xiao Yu, que está tratando de crear la instancia del controlador de cromo antes de establecer la ruta de acceso en propiedad del sistema. Puede actualizar el código como se muestra a continuación

public class Main {
    static Locators Locators = new Locators();
    static WebDriver driver;

    public static void main(String[] args) {
        System.setProperty("webdriver.chrome.driver", "C:\\Users\\currentuser\\chromedriver.exe");
        driver =  new ChromeDriver();
    }

Supongo que te gusta

Origin http://43.154.161.224:23101/article/api/json?id=318753&siteId=1
Recomendado
Clasificación