private void Save_Click(object sender, RoutedEventArgs e) { string path = tbFirefoxpath.Text.Trim(); if (!string.IsNullOrEmpty(path)) { var x = new BrowserPath { Path = path }; using (StreamWriter file = File.CreateText(browserPath)) { new JsonSerializer().Serialize(file, x); } } Close(); }
public void BuildDriver() { try { BrowserPath path = new BrowserPath { Path = "" }; if (File.Exists(browserPath)) { using (StreamReader file = File.OpenText(browserPath)) { JsonTextReader jsonReader = new JsonTextReader(file); path = new JsonSerializer().Deserialize <BrowserPath>(jsonReader); } } FirefoxDriverService ffService = FirefoxDriverService.CreateDefaultService("Driver"); // driver path ffService.FirefoxBinaryPath = path.Path; ffService.HideCommandPromptWindow = true; FirefoxOptions ffOpt = new FirefoxOptions(); this.Driver = new FirefoxDriver(ffService, ffOpt, TimeSpan.FromSeconds(60.0)); OnDriverBuilt(); } catch (WebDriverException e) when(e.Message.Contains("Expected browser binary location")) { OnBrowserPathError(); Console.WriteLine(e.ToString()); } catch (InvalidOperationException e) { OnBrowserPathError(); Console.WriteLine(e.ToString()); } catch (Exception e) { Console.WriteLine(e.ToString()); } }