private static string GetChromeFile()
{
if (!IsChromeBinaryLocationKnown())
{
string chromeFileSystemProperty = Environment.GetEnvironmentVariable("webdriver.chrome.bin");
if (chromeFileSystemProperty != null)
{
chromeFile = chromeFileSystemProperty;
}
else
{
if (Platform.CurrentPlatform.IsPlatformType(PlatformType.XP) || Platform.CurrentPlatform.IsPlatformType(PlatformType.Vista))
{
try
{
chromeFile = ChromePathFromRegistry;
}
catch (NullReferenceException)
{
if (Platform.CurrentPlatform.IsPlatformType(PlatformType.XP))
{
chromeFile =
Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
"Google\\Chrome\\Application\\chrome.exe");
}else
{
chromeFile = Path.Combine(Path.GetTempPath(),
"..\\Google\\Chrome\\Application\\chrome.exe");
}
}
}
else if (Platform.CurrentPlatform.IsPlatformType(PlatformType.Unix))
{
// Thanks to a bug in Mono Mac and Linux will be treated the same https://bugzilla.novell.com/show_bug.cgi?id=515570 but adding this in case
string chromeFileString = string.Empty;
bool foundPath = false;
foreach (string path in chromePaths)
{
FileInfo binary = new FileInfo(path);
if (binary.Exists)
{
chromeFileString = binary.FullName;
foundPath = true;
break;
}
}
if (!foundPath)
{
throw new WebDriverException("Couldn't locate Chrome. Set webdriver.chrome.bin");
}
chromeFile = chromeFileString;
}
else
{
throw new WebDriverException(
"Unsupported operating system. Could not locate Chrome. Set webdriver.chrome.bin");
}
}
}
return chromeFile;
}