title: WPF application starts console after click button and crashes xaml
body: <p>I created a Selenium Console Bot which now I want to be started with WPF. So I created a simple window and added a button, which is supposed to start my bot, which I've rewritten into WPF. It starts and it works, but it crashes the xaml window and opens a Console (which shouldn't happen or should?). Then it leaves the console empty and writes down what it should in Visual Studio console. It happens when I start method <code>CheckItems(_driver)</code>. Any possible solutions? I don't mind starting a console to run in the background, but why does it crash the main window so I can not move it or do anything with it?</p>
  
  <pre><code>private IWebDriver Setup(IWebDriver driver)
      {
  
          var option = new ChromeOptions();
          option.AddArgument("--headless");
          option.AddArgument("--silent");
          option.AddArgument("--disable-gpu");
          option.AddArgument("--log-level=3");
  
  
          var service = ChromeDriverService.CreateDefaultService();
          service.SuppressInitialDiagnosticInformation = true;
  
  
          _driver = new ChromeDriver(service, option);
  
  
          //driver.Navigate().GoToUrl("");
  
  
          _driver.Navigate().GoToUrl("urlofmychoice");
          _driver.Manage().Window.Maximize();
  
          _driver.Manage().Timeouts().ImplicitWait =
              TimeSpan.FromSeconds(7); // breaks in between actions taken by webDriver
          _driver.FindElement(By.XPath("/html/body/div[2]/div/a")).Click(); // click got it (need to add fake cookie)
          _driver.FindElement(By.Id("header-email"))
              .SendKeys("myemail"); // enters my login (need to make it adjustable)
          _driver.FindElement(By.Id("header-password"))
              .SendKeys("mypassword" + Keys.Enter); // enters my password (need to make it adjustable)
  
          var username = _driver.FindElement(By.XPath("/html/body/header/section[1]/div/div[2]/div/a/span"))
              .Text; // Get username from the site and saves to username
  
  
          tradeUrl = "ulrIneed" + username; // initialize tradeUrl
  
  
          //_driver.Navigate().GoToUrl(tradeUrl); // goes to tradeUrl
  
  
          return _driver;
      }
  
   private void CheckItems(IWebDriver driver)
      {
  
          while (true)
          {
  
              _driver.Navigate().GoToUrl(tradeUrl);
              var trades = _driver.FindElements(By.ClassName("rlg-trade-display-header")); // add all trades to list
  
              for (var i = 0; i &lt; trades.Count; i++) // loop to check all trades
              {
                  if (i == 0)
  
                      Console.WriteLine("\n    Active Trades: " + trades.Count);
                  var text = _driver
                      .FindElement(By.XPath(
                          "/html/body/main/div/div/div/div[4]/div[" + (i + 1) + "]/div[1]/div/div/span"))
                      .Text.Split(); // reads text from trade and adjust it for the program
                  var test = "Trade " + (i + 1) + " was last updated " + text[1] + " " + text[2] + " ago.";
                  Console.WriteLine(test);
  
  
                  var x = int.Parse(text[1]); // convert string to int to check time later
  
                  if (text[2] == "seconds")
                      continue;
  
  
                  if (text[2] == "hours" || text[2] == "hour" || text[2] == "days" || text[2] == "day" ||
                      text[2] == "month" || text[2] == "months" || x &gt; 15)
                  {
                      var element1 =
                          _driver.FindElement(By.XPath("/html/body/main/div/div/div/div[4]/div[" + (i + 1) +
                                                       "]/div[1]/a/div"));
                      var actions1 = new Actions(_driver);
                      actions1.MoveToElement(element1).Click()
                          .Perform(); // scrolls down to choosen element and clicks it
  
  
                      _driver.FindElement(By.XPath("/html/body/main/div/div/div/div[2]/a[1]"))
                          .Click(); // click choosen element
  
  
                      var element = _driver.FindElement(By.Name("btnSubmit"));
                      var actions = new Actions(_driver);
                      actions.MoveToElement(element).Click()
                          .Perform(); // scrolls down to choosen element and clicks it
                      driver.Navigate().GoToUrl(tradeUrl);
                      Thread.Sleep(2000);
                  }
              }
              Thread.Sleep(15000); // wait 15 second before next loop
          }
      }
  
  
  
  
     private void BtnStart_OnClick(object sender, RoutedEventArgs e)
      {
  
          Setup(_driver);
          CheckItems(_driver);
  
      }
  }
  </code></pre>