title: Selenium - Cannot Connect to Remote Server
body: <p>let me first drop you the error then I'll explain the context and finally I will show the code and explain that. </p>
  
  <p><strong>Error</strong>
  <a href="https://i.stack.imgur.com/JjIop.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/JjIop.png" alt="enter image description here"></a></p>
  
  <p>Here is the same/similar error using FirefoxDriver
  <a href="https://i.stack.imgur.com/5XoqJ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/5XoqJ.png" alt="enter image description here"></a></p>
  
  <p><strong>Context</strong></p>
  
  <p>I made a program to go through websites and gather some data. This <strong>program works 100% on my local desktop windows 7 professional</strong> but when I move it to my server which is a windows 2003 server with .net framework 3.5 it throws the above error. </p>
  
  <p>Note that the application is multithreaded in the case above there are two threads running 2 instances of selenium. The problem with the application occurs when they finished gathering the list of links they want to explore. One thread will work find and go through the list of links one by one, when they other one finishes gathering the links it wants to explore both of the selenium clients break and start throwing the error above. </p>
  
  <p>I didn't use any functions not meant for .net framework 3.5.... Everything is standardized to fit the 2003 server (at least to my knowledge). </p>
  
  <p><strong>Code</strong></p>
  
  <p>When it is collecting links:</p>
  
  <pre><code>  List&lt;string&gt; totalList = new List&lt;string&gt;();
                  if (loadedSave == null)
                  {
                      webManager.driver.Navigate().GoToUrl(getOffenderListURL(countyId));
                      for (int l = 2; l &lt; 10000; l++)
                      {
                          try
                          {
                              var element1 = new WebDriverWait(webManager.driver, TimeSpan.FromSeconds(5)).Until(ExpectedConditions.ElementExists((By.XPath(getOffenderxPath(l)))));
  
                              string linkToOffender = element1.GetAttribute("href");
                              string offenderId = linkToOffender.Substring(linkToOffender.IndexOf('=') + 1);
                              if (totalList.Contains(offenderId))
                              {
                                  continue;
                              }
                              totalList.Add(offenderId);
  //----- ^^^^^ Add the links/ids to a list for later-----
                          }
                          catch (Exception e)
                          {
  // ignore this error catch.... its not relevant 
                              if (totalList.Count &lt; 5 &amp;&amp; countyId != 21)
                              {
                                  if (Program.SiteDownCounter &lt; 4)
                                  {
                                      if (Program.LastDown != DateTime.MinValue)
                                      {
                                          if ((DateTime.Now - Program.LastDown).TotalMinutes &gt; 30)
                                          {
                                              Program.sendMail("NY State website seems to be down... will suspend action for 30 minutes. Current time: " + DateTime.Now, "NY State Site Down!");
                                              Program.LastDown = DateTime.Now;
                                              Program.SiteDownCounter++;
                                              for (int x = 0; x &lt; 30; x++)
                                                  Thread.Sleep(1000);
                                          }
                                          else
                                          {
                                              Thread.Sleep((1800 - (int)((DateTime.Now - Program.LastDown).TotalSeconds)) * 1000);
                                          }
                                      }
                                      else
                                      {
                                          Program.sendMail("NY State website seems to be down... will suspend action for 30 minutes. Current time: " + DateTime.Now, "NY State Site Down!");
                                          Program.LastDown = DateTime.Now;
                                          Program.SiteDownCounter++;
                                          for (int x = 0; x &lt; 30; x++)
                                              Thread.Sleep(1000);
                                      }
                                  }
                                  else
                                  {
                                      start = false;
                                      break;
                                  }
                                  continue;
                              }
                              break;
                          }
                      }
                  }
                  else
                  {
                      if (loadedSave.CompletedList != null)
                          totalList = loadedSave.CompletedList;
                      else
                      {
                          Console.WriteLine("The hell?");
                      }
  
                  }
                  Program.LastDown = DateTime.MinValue;
                  Program.SiteDownCounter = 0;
                  ScrapeLogic(countyId, out2, loadedSave, totalList);
              }
  </code></pre>
  
  <p>As soon as its done collecting the links: </p>
  
  <pre><code> private void ScrapeLogic(int countyId, string value, ScraperStateSave LoadedSaveState, List&lt;string&gt; total)
          {
              ScraperStateSave saveState = new ScraperStateSave();
              saveState.CountyId = countyId;
              int totalCompletedCount = (LoadedSaveState != null ? LoadedSaveState.CompletedCount : 0);
              int instanceCompletedCount = 0;
              for (int l = totalCompletedCount; l &lt; total.Count; l++)
              {
                  try
                  {
                      if (Program.SiteDownCounter &gt;= 3)
                          throw new Exception("Shutdown");
                      webManager.driver.Navigate().GoToUrl(getOffenderLinkById(total[l]));
                      string offenderId = total[l];
                      var currentPlacement = webManager.getElementTextByxPath(currentPlacementxPath, true);
                      Boolean wanted = false;
                      try
                      {
                         IWebElement wantedLabel = webManager.driver.FindElement(By.XPath("//*[@id=\"mainContent\"]/h3[2]"));
                         wanted = true;
                      }
                      catch (NoSuchElementException)
                      {
  
                      }
                      var lastName = webManager.getElementTextByxPath(getOffenderInfoBasic(1, 2));
                      var firstName = webManager.getElementTextByxPath(getOffenderInfoBasic(1, 3));
                      var middleName = webManager.getElementTextByxPath(getOffenderInfoBasic(1, 4));
                      var dob = webManager.getElementTextByxPath(getOffenderInfoBasic(1, 5));
                      var sex = webManager.getElementTextByxPath(getOffenderInfoBasic(1, 6));
                      var riskLevel = webManager.getElementTextByxPath(getOffenderInfoBasic(1, 7));
                      var designation = webManager.getElementTextByxPath(getOffenderInfoBasic(1, 8));
  ....and more of the same
  </code></pre>
  
  <p>How the thread starts: </p>
  
  <pre><code> public NYScaper(Boolean local, Boolean quiet, int id)
      {
          this.localScrape = local;
          this.threadId = id;
          this.quiet = quiet;
          Thread t = new Thread(doScrape);
          t.Start();
      }
  </code></pre>
  
  <p>Some code that may be in question: </p>
  
  <pre><code>  public IWebElement getElementByxPath(string xpath) 
          {
              return driver.FindElement(By.XPath(xpath));
          }
  
  
          public string getElementTextByxPath(string xpath)
          {
              return driver.FindElement(By.XPath(xpath)).Text;
          }
  
          public string getElementTextByxPath(string xpath, Boolean wait)
          {
              return new WebDriverWait(driver, TimeSpan.FromSeconds(2)).Until(ExpectedConditions.ElementExists((By.XPath(xpath)))).Text;
          }
  </code></pre>
  
  <p><strong>Main problem/Overview:</strong></p>
  
  <p><strong>Works on Windows 7 Professional but not 2003 server! Errors only seem to come up between link collecting and data collection or at the beginning of data collection. There are two threads and they work on local windows 7 desktop without issues. If the program is restarted it will load a save of the links and it will work with those saved links without the errors shown!</strong></p>