title: Selenium webdriver window handles c# switchTo failed
body: <p>Here comes 2 windows pop out during the testing.</p>
  
  <p>my code:</p>
  
  <pre><code>string BaseWindow = driver.CurrentWindowHandle;                 
  ReadOnlyCollection&lt;string&gt; handles = driver.WindowHandles;
  
  foreach(string handle in handles)                    
  {                         
      Boolean a = driver.SwitchTo().Window(handle).Url.Contains("Main");
      if (a == true)  
      {       
          InitialSetting.driver.SwitchTo().Window(handle);      
          break;
      }  
  }                
  </code></pre>
  
  <p>I want to switch to the window which url contains "Main". But when the test is running, it switches between two windows continuously and it doesn't stop.</p>
  
  <p>I debug and found the <code>foreach</code> didn't break even when the <code>boolean a</code> is true.</p>
  
  <p>How can I resolve this? </p>