title: Selenium switching windows failure
body: <p>I am writing a web scraper using Selenium which needs to be multi-threaded</p>
  
  <pre><code>// selenium imports from org.openqa omitted
  public class wpn
  {
      private String sessionId = "";
      private String windowHandle = "";
      private WebDriver driver;
  
      public wpn (String id)
      {
          sessionId = id;
      }
  
      public void openDriver (String driverType)
      {
          if (driverType.equals ("ie"))
          {
              DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer();
              capabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
              capabilities.setCapability(InternetExplorerDriver.IE_ENSURE_CLEAN_SESSION, true);
              capabilities.setCapability("requireWindowFocus", true);
              System.setProperty("webdriver.ie.driver", "c:\\temp\\ieDriver.exe");
              driver = new InternetExplorerDriver(capabilities);
              driver.manage().window().maximize();
          }
          else if (driverType.equals ("chrome"))
          {
              DesiredCapabilities capabilities = DesiredCapabilities.chrome();
              capabilities.setCapability(CapabilityType.ForSeleniumServer.ENSURING_CLEAN_SESSION, true);
              System.setProperty("webdriver.chrome.driver", "c:\\temp\\chromedriver.exe");
              driver = new ChromeDriver (capabilities);
              driver.manage().window().maximize();
          }
          else if (driverType.equals ("phantom"))
          {
              File file = new File("c:\\temp\\phantomJSDdriver.exe");
              System.setProperty("phantomjs.binary.path", file.getAbsolutePath ());
              DesiredCapabilities capabilities = new DesiredCapabilities();
              capabilities.setJavascriptEnabled(true);
              capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS, new String[] {"--web-security=no", "--ignore-ssl-errors=yes"});
              driver = new PhantomJSDriver(capabilities);
              Dimension dimension = new Dimension (1280, 1024);
              driver.manage().window().setSize (dimension);
          }
          else if (driverType.equals ("firefox"))
          {
              System.setProperty ("webdriver.gecko.driver", "c:\\temp\\geckodriver.exe");
              FirefoxOptions options = new FirefoxOptions ();
              options.setBinary (c:\\temp\\firefoxdriver.exe");
              options.addArguments("--headless");
              driver = new FirefoxDriver(options);
              driver.manage().window().maximize();
          }
          else
          {
              System.println("unrecognised driver type " + driverType); 
          }
  
          System.setProperty ("https.protocols", "TLSv1.2");
      }
  
      public void login (String loginUrl)
      {
          driver.get(loginUrl);
          windowHandle = driver.getWindowHandle ();
      }
  
      public void getInfo (String infoUrl)
      {
          try
          {
              String wh = driver.getWindowHandle ();
              if (!wh.matches(windowHandle))
              {
                  driver.switchTo(windowHandle);
              }
  
              driver.get(infoUrl);
          }
          catch (Exception e)
          {
              System.out.println (e.getMessage ());
          }
      }
  }
  
  int main (String[] args)
  {
      wpn session_1 = new wpn ("101");
      wpn session_2 = new wpn ("202");
  
      String driverType = args[0];
      session_1.openDriver (driverType);
      session_2.openDriver (driverType);
  
      session_1.login ("http://myService.com/login");
      session_2.login ("http://myService.com/login");
  
      session_2.info ("http://myService.com/info");
      // proceeds OK, because window handles match
  
      session_1.info ("http://myService.com/info");
      // produces failure when attempting to switch to session_1's window
  }
  </code></pre>
  
  <p>With the ie driver, the error is something like:</p>
  
  <pre><code>No window found  
  Build info: version: '3.5.0', revision: '8def36e068', time: '2017-08-10T23:00:22.093Z'  
  System info: host: 'HUWG', ip: '192.168.0.215', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_144'  
  Driver info: org.openqa.selenium.ie.InternetExplorerDriver  
  Capabilities [{acceptInsecureCerts=false, browserVersion=11, se:ieOptions={nativeEvents=true, browserAttachTimeout=0.0, ie.ensureCleanSession=true, elementScrollBehavior=0.0, enablePersistentHover=false, ie.browserCommandLineSwitches=, ie.forceCreateProcessApi=false, requireWindowFocus=true, initialBrowserUrl=http://localhost:40976/, ignoreZoomSetting=false, ie.fileUploadDialogTimeout=3000.0, ignoreProtectedModeSettings=true}, browserName=internet explorer, pageLoadStrategy=normal, unhandledPromptBehavior=dismiss, javascriptEnabled=true, platformName=windows, setWindowRect=true, platform=ANY}]  
  Session ID: cd72bba0-f105-43a8-a234-cbb494c19d8c  
  </code></pre>
  
  <p>With Chrome it is something like:</p>
  
  <pre><code>no such window  
    (Session info: chrome=67.0.3396.99)  
    (Driver info: chromedriver=2.40.565498  
   (ea082db3280dd6843ebfb08a625e3eb905c4f5ab),platform=Windows NT 6.1.7601 SP1 x86_64) (WARNING: The server did not provide any stacktrace information)  
  Command duration or timeout: 0 milliseconds  
  Build info: version: '3.13.0', revision: '2f0d292', time: '2018-06-25T15:32:19.891Z'  
  System info: host: 'HUWG', ip: '192.168.0.215', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_144'  
  Driver info: org.openqa.selenium.chrome.ChromeDriver  
  Capabilities {acceptInsecureCerts: false, acceptSslCerts: false, applicationCacheEnabled: false, browserConnectionEnabled: false, browserName: chrome, chrome: {chromedriverVersion: 2.40.565498 (ea082db3280dd6..., userDataDir: C:\Users\gallonh\AppData\Lo...}, cssSelectorsEnabled: true, databaseEnabled: false, handlesAlerts: true, hasTouchScreen: false, javascriptEnabled: true, locationContextEnabled: true, mobileEmulationEnabled: false, nativeEvents: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: XP, platformName: XP, rotatable: false, setWindowRect: true, takesHeapSnapshot: true, takesScreenshot: true, unexpectedAlertBehaviour: , unhandledPromptBehavior: , version: 67.0.3396.99, webStorageEnabled: true}  
  Session ID: c4c74d5258c723a0a09dbbf7284b1c48
  </code></pre>
  
  <p>With phantomJS driver, it is something like:</p>
  
  <pre><code>no such window  
    (Session info: chrome=67.0.3396.99)  
    (Driver info: chromedriver=2.40.565498  
   (ea082db3280dd6843ebfb08a625e3eb905c4f5ab),platform=Windows NT 6.1.7601 SP1 x86_64) (WARNING: The server did not provide any stacktrace information)  
  Command duration or timeout: 0 milliseconds  
  Build info: version: '3.13.0', revision: '2f0d292', time: '2018-06-25T15:32:19.891Z'  
  System info: host: 'HUWG', ip: '192.168.0.215', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_144'  
  Driver info: org.openqa.selenium.chrome.ChromeDriver  
  Capabilities {acceptInsecureCerts: false, acceptSslCerts: false, applicationCacheEnabled: false, browserConnectionEnabled: false, browserName: chrome, chrome: {chromedriverVersion: 2.40.565498 (ea082db3280dd6..., userDataDir: C:\Users\gallonh\AppData\Lo...}, cssSelectorsEnabled: true, databaseEnabled: false, handlesAlerts: true, hasTouchScreen: false, javascriptEnabled: true, locationContextEnabled: true, mobileEmulationEnabled: false, nativeEvents: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: XP, platformName: XP, rotatable: false, setWindowRect: true, takesHeapSnapshot: true, takesScreenshot: true, unexpectedAlertBehaviour: , unhandledPromptBehavior: , version: 67.0.3396.99, webStorageEnabled: true}  
  Session ID: c4c74d5258c723a0a09dbbf7284b1c48
  </code></pre>
  
  <p>With the Firefox driver, the handle for every  window opened by Selenium is "4294967297" so the window is never switched.</p>
  
  <p>For the IE and phantomJS drivers I am building the application with selenium-server-standalone-3.5.0.jar. For the chrome and firefox drivers I am building the application with selenium-server-standalon-3.13.0.jar.</p>