Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Where to set the path to webdriver.chrome.driver (Java, Selenium, IntelliJ)?

So I’m working with Selenium IDE and it beautifully generated the code for me. But I have an issue with webdriver. This is the code.

package org.example;// Generated by Selenium IDE
        import org.junit.Test;
        import org.junit.Before;
        import org.junit.After;
        import org.openqa.selenium.By;
        import org.openqa.selenium.WebDriver;
        import org.openqa.selenium.chrome.ChromeDriver;
        import org.openqa.selenium.Dimension;
        import org.openqa.selenium.WebElement;
        import org.openqa.selenium.interactions.Actions;
        import org.openqa.selenium.JavascriptExecutor;
        import java.util.*;
public class StorwareTestTest {
        WebDriver driver;
        Map<String, Object> vars;
        JavascriptExecutor js;
        @Before
        public void setUp () {
            driver = new ChromeDriver();
            js = (JavascriptExecutor) driver;
            vars = new HashMap<String, Object>();
        }
        @After
        public void tearDown () {
            driver.quit();
        }
        @Test
        public void storware () {
            System.setProperty("webdriver.chrome.driver", "C:/Users/wrost/Downloads/chromedriver_win32/chromedriver.exe");

            driver.get("https://storware.eu/");
    (...)
            

So, the compiler is yelling at me that: The path to the driver executable must be set by the webdriver.chrome.driver system property;
But I did it. Maybe in the wrong place. What can I do to fix it? I’ve been working on it for 2 hours, and honestly have no idea. Maybe it’s some basic problem. I’m a fresher. And the code is autogenerated by SeleniumIDE, so it probably does a bunch of stuff I don’t even know about. Maybe it shouldn’t be under @Test annotation. But then where? (When I was writing basic programs using Selenium with Java everything worked. But I also want to know how SeleniumIDE works, and that’s where the problems started).
Thanks for Your help!

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Ideally the System.setProperty() line should be mentioned before you initialize the ChromeDriver driven browsing context.

Effectively your code block will be:

@Before
public void setUp () {
    System.setProperty("webdriver.chrome.driver", "C:/Users/wrost/Downloads/chromedriver_win32/chromedriver.exe");
    driver = new ChromeDriver();
    js = (JavascriptExecutor) driver;
    vars = new HashMap<String, Object>();
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading