Getting “The path to the driver executable must be set by the webdriver.chrome.driver system property”though set correct path

前端 未结 10 1583
攒了一身酷
攒了一身酷 2020-12-10 11:30

My code is very simple code:

WebDriver wd =new ChromeDriver();
  System.setProperty("webdriver.chrome.driver",
                     "D:\\\\List         


        
相关标签:
10条回答
  • 2020-12-10 11:57

    If you are using IntelliJ IDE, then on IntelliJ without setting up within the 'Run > Edit configurations > VM Options' i will just meet this error:

    Failed scenarios:
    C:/Users/DATestAdmin/IdeaProjects/TestLogin/src/test/resources/login.feature:4 # Scenario: Successfully logging in
    
    1 Scenarios (1 failed)
    3 Steps (3 skipped)
    0m0.194s
    
    java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.chrome.driver system property;
    

    So once i've added the path to my chromedriver locally in 'Run > Edit configurations > VM Options':

    -Dwebdriver.chrome.driver="C:\\Users\\This\\Is\\Where\\ChromeDriverIs\\chromedriver_win32.exe"
    

    Run > Edit Configurations

    I'm now able to launch my Chrome browser successfully.

    0 讨论(0)
  • 2020-12-10 12:08

    I was getting the same error, since chrome driver was not installed on my machine. Install the chrome driver. Follow: https://github.com/SeleniumHQ/selenium/wiki/ChromeDriver

    0 讨论(0)
  • 2020-12-10 12:10

    You should use Chocolatey as the Selenium wiki dictates. It will work straight away.

    Windows users with Chocolatey installed: choco install chromedriver

    https://github.com/SeleniumHQ/selenium/wiki/ChromeDriver

    0 讨论(0)
  • 2020-12-10 12:11

    You are setting chrome driver path incorrectly. Property must be set before WebDriver initialization.

    Set property like this -

    System.setProperty("webdriver.chrome.driver","D:\\List_of_Jar\\chromedriver.exe")
    WebDriver wd =new ChromeDriver();
    String baseUrl = "https://www.google.com";
    wd.get(baseUrl);" 
    
    0 讨论(0)
  • 2020-12-10 12:11

    Try:

    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.chrome.ChromeDriver;
    
    public class Demo2 {
    
        public static void main(String[] args) {
            // TODO Auto-generated method stub
    
            System.setProperty("webdriver.chrome.driver", "I:\\Bhasker-ShiroCode\\work\\chromedriver.exe");
    
            WebDriver driver = new ChromeDriver();
    
            driver.get("http://google.com");
        }
    
    }
    

    To avoid Error:

    • webdriver.chrome.driver ( should be in small letters )
    • have to give correct chromedriver.exe ( correct path )
    • Import all Selenium jars under class Path
    0 讨论(0)
  • 2020-12-10 12:13

    I totally agree with Murthi, but better is to set relative path to the driver, NOT the absolute.

    Relative path looks like:

    System.setProperty("webdriver.chrome.driver", "src/test/resources/drivers/chromedriver.exe");
    

    Abosulte: is the path to the driver in your PC.

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

    Why? It is a good practice to have driver inside your project, not just in your computer. Just find or create folder f.e. resources, inside resources create folder called f.e. drivers and import your driver/drivers exe files there.

    0 讨论(0)
提交回复
热议问题