16

how can i set system properties in C#.

In java i can use:

System.setProperty("webdriver.chrome.driver","/path/to/where/you/ve/put/chromedriver.exe");

how to do this in C#?

senzacionale
  • 20,448
  • 67
  • 204
  • 316

6 Answers6

23

try System.Environment.SetEnvironmentVariable("webdriver.chrome.driver",@"/path/to/where/you/ve/put/chromedriver.exe")
-MSDN

Damith
  • 62,401
  • 13
  • 102
  • 153
11

There's no equivalent of "system properties" in C#. They're a Java-specific concept. (They're not really system properties in Java - they're JVM-wide-properties, some of which are derived from system environment variables etc.)

You should look in the WebDriver documentation for how to set this for the .NET version.

EDIT: Just to clarify, System.Environment.SetEnvironmentVariable could be used in a similar way, but it tends not to be in my experience.

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
  • I believe `System.Environment` is a good an equivalent. What do you think? – manojlds Aug 24 '11 at 18:38
  • @manojlds: Well, it's not really the same... and typically not *used* in the same way. Quite a few Java libraries use system properties (although I'm not a fan of that) - I can't remember seeing any .NET ones which do... – Jon Skeet Aug 24 '11 at 19:56
2

System.Environment will provide you some "properties" but this is a Java specific concept which will not have any direct equivalent in C#.

Madhan
  • 5,750
  • 4
  • 28
  • 61
manojlds
  • 290,304
  • 63
  • 469
  • 417
1

You need to start Selenium Server with the following option: Dwebdriver.chrome.driver=c:\path\to\your\chromedriver.exe

Like this: java -jar selenium-server-standalone-2.42.0.jar -role node -hub http://localhost:4444/grid/register -Dwebdriver.chrome.driver=c:\path\to\your\chromedriver.exe

vasin
  • 474
  • 5
  • 15
1

I realize that this thread is really old, but if you ended up on this page, an alternative solution is to add chromedriver.exe to your project, set Build Action to "Content" and set Copy to Output Directory to "Copy if newer". Then you can skip setting the environment variable.

The drawback to this solution is that you'll end up with multiple copies of a 5 MB file.

Brad Allan
  • 11
  • 2
0

Take a look at Environment class, you could set some of the properties there.

JAiro
  • 5,914
  • 2
  • 22
  • 21