Not getting setProperty method for System Class

No, it won’t work like that.

You’d have to write one static or instance method, and inside that you can write:

System.setProperty("webdriver.gecko.driver", "C:\\Users\\***\\Downloads\\chromedriver_win32\\geckodriver.exe");  

Using raw Selenium and Java, you could create a main method and set the system property:

 public static void main(String[] args) {
         System.setProperty("webdriver.gecko.driver", "C:\\Users\\***\\Downloads\\chromedriver_win32\\geckodriver.exe");
    }  

Or if you are using TestNG then you could do something like this:

public class NewTest {

     public WebDriver driver;

     @BeforeClass
      public void beforeClass() {
         System.setProperty("webdriver.gecko.driver", "C:\\Users\\***\\Downloads\\chromedriver_win32\\geckodriver.exe");
         driver =  new FirefoxDriver();

      }

      @Test
      public void openMyBlog() {
            driver.get("http://www.google.com");
            System.out.println("This is first test");
      }
}

Leave a Comment