public static IWebDriver CreateChromeGridDriver(string profileName, string hubAddress)
{
if (hubAddress == null)
{
throw new ArgumentException("remoteAddress");
}
var chromeOptions = new ChromeOptions();
if (!string.IsNullOrWhiteSpace(profileName))
{
var fileChars = Path.GetInvalidFileNameChars();
var pathChars = Path.GetInvalidFileNameChars();
var invalidChars = fileChars.Union(pathChars);
profileName = String.Join("", profileName.Where(c => !invalidChars.Contains(c)));
chromeOptions.AddArguments(String.Format("user-data-dir=c:\\ChromeProfiles\\{0}", profileName));
}
RemoteWebDriver Driver = new RemoteWebDriver(new Uri(hubAddress), chromeOptions.ToCapabilities());
Driver.Manage().Timeouts().SetPageLoadTimeout(new TimeSpan(0, 1, 0));
Driver.Manage().Timeouts().ImplicitlyWait(new TimeSpan(0, 0, 1));
Driver.Manage().Window.Maximize();
return Driver;
}