title: Selenium WebDriver, when loading an HTTPS website, closes and reopens browser and does not even attempt to interact with the DOM
body: <p>Selenium WebDriver (run from Eclipse Oxygen.3a Release (4.7.3a)) seems to be unable to handle any HTTPS website.</p>
  
  <p>By that I mean this: upon loading the page (regardless of whether it redirects or not, tried with gitlab and AWS logon sites)</p>
  
  <ul>
  <li>Logon page loads properly (no SSL certificate issues, any redirect happens just fine), yet Selenium doesn't do anything (debug mode shows it's not even trying to execute the logon code)</li>
  <li>It times out (browserWaitTimeout=15) and closes/reopens the logon page</li>
  <li>This happens until the 4th time, upon which Selenium finally reaches my logon code (a breakpoint I set there is finally hit), but this happens between browser page closing and reopening, thus it never detects the DOM and fails.</li>
  </ul>
  
  <p>And the most frustrating thing is, console shows NO ERRORS.
  Here: Chrome:</p>
  
  <pre><code>Jul 03, 2019 8:40:44 AM com.fincad.vcr.qa.support.WebDriverFactory createWebDriver
  
  INFO: Web driver is created successfully
  
  Jul 03, 2019 8:40:55 AM com.fincad.vcr.qa.support.WebDriverFactory quitWebDriver
  
  INFO: Web driver quits successfully
  </code></pre>
  
  <p>That's it, as in literally it (notice the 15 second gap? That's browserWaitTimeout).</p>
  
  <p>a) I tried FF, where I saw errors from Marionette:</p>
  
  <pre><code>1562172157538   Marionette  INFO    Listening on port 56792
  
  1562172157572   addons.xpi-utils    DEBUG   Successfully read XPI database
  
  1562172157603   addons.manager  DEBUG   Registering upgrade listener for 
  formautofill@mozilla.org
  
  Jul 03, 2019 9:42:37 AM org.openqa.selenium.remote.ProtocolHandshake createSession
  
  INFO: Detected dialect: W3C
  
  Jul 03, 2019 9:42:38 AM com.fincad.vcr.qa.support.WebDriverFactory createWebDriver
  
  INFO: Web driver is created successfully
  
  1562172170219   Marionette  INFO    Stopped listening on port 56792
  
  1562172170243   addons.xpi  DEBUG   Calling bootstrap method shutdown on webcompat@mozilla.org version 4.0.0
  
  1562172170249   addons.xpi  DEBUG   Calling bootstrap method shutdown on screenshots@mozilla.org version 37.1.0
  
  1562172170253   addons.xpi  DEBUG   Calling bootstrap method shutdown on fxmonitor@mozilla.org version 3.0
  
  1562172170254   addons.xpi  DEBUG   Calling bootstrap method shutdown on formautofill@mozilla.org version 1.0
  
  [Parent 12824, Gecko_IOThread] WARNING: pipe error: 109: file z:/task_1560988628/build/src/ipc/chromium/src/chrome/common/ipc_channel_win.cc, line 341
  
  [Child 21788, Chrome_ChildThread] WARNING: pipe error: 109: file z:/task_1560988628/build/src/ipc/chromium/src/chrome/common/ipc_channel_win.cc, line 341
  
  [Child 21788, Chrome_Chi[Parent 12824, Gecko_IOThread] WARNING: pipe error: 109: file z:/task_1560988628/build/src/ipc/chromium/src/chrome/common/ipc_channel_win.cc, line 341
  
  [Child 6644, Chrome_ChildThread] WARNING: pipe error: 109: file z:/task_1560988628/build/src/ipc/chromium/src/chrome/common/ipc_channel_win.cc, line 341
  
  [Child 6644, Chrome_ChildThread] WAR[Parent 12824, Gecko_IOThread] WARNING: pipe error: 109: file z:/task_1560988628/build/src/ipc/chromium/src/chrome/common/ipc_channel_win.cc, line 341
  
  [Child 17844, Chrome_ChildThread] WARNING: pipe error: 109: file z:/task_1560988628/build/src/ipc/chromium/src/chrome/common/ipc_channel_win.cc, line 341
  
  [Child 17844, Chrome_ChildThread] WARNING: pipe er[Parent 12824, Gecko_IOThread] WARNING: pipe error: 109: file z:/task_1560988628/build/src/ipc/chromium/src/chrome/common/ipc_channel_win.cc, line 341
  
  [Chi###!!! [Parent][MessageChannel] Error: (msgtype=0x1F0099,name=PBrowser::Msg_UpdateNativeWindowHandle) Closed channel: cannot send/recv
  </code></pre>
  
  <p>I googled and people mentioned it's due to outdated FF driver, so I upgraded, but it didn't do any good (same errors appear). And in IE it's like Chrome: no error or warning msg at all.</p>
  
  <p>My drivers are these:
  Selenium WebDriver: 3.14.0 (32-bit)
  geckodriver 0.24.0 (32-bit)
  chromedriver 74.0.3729.6 (32-bit)
  IEDriverServer 3.8.0 (32-bit)</p>
  
  <p>And my browsers:
  Chrome browser: 75.0.3770.100
  FF browser: 67.0.4 
  IE browser: 11.557.17763</p>
  
  <p>This is how I create my drivers:</p>
  
  <pre><code>private static void createFirefoxDriver() {
      setCapability("firefox");
      GeckoDriverService.Builder builder = new GeckoDriverService.Builder();
      GeckoDriverService service = builder.build();
      FirefoxOptions options = new FirefoxOptions(capabilities);
      // Read the default firefox profile
      ProfilesIni profile = new ProfilesIni();
      FirefoxProfile myProfile = profile.getProfile("default");
      // Disable the web page from asking if really want to leave
      myProfile.setPreference("dom.disable_beforeunload", true);
      options.setProfile(myProfile);
      driver = new FirefoxDriver(service, options);
  }
  
  private static void createChromeDriver() {
      setCapability("chrome");
      ChromeDriverService.Builder builder = new ChromeDriverService.Builder();
      ChromeDriverService service = builder.build();
      ChromeOptions options = new ChromeOptions();
      options.merge(capabilities);
      driver = new ChromeDriver(service, options);
  }
  </code></pre>
  
  <p>This is how I load the URL (local webdriver):</p>
  
  <pre><code>private static void createLocalWebDriver() {
      String browser = ConfigParser.getBrowser();
      LOGGER.info("Target Browser: " + browser);
  
      switch (browser) {
          case "firefox":
              System.setProperty("webdriver.gecko.driver", ConfigParser.getGeckoDriver());
              System.out.println("GeckoDriver on: " + ConfigParser.getGeckoDriver());
              createFirefoxDriver();
              break;
          case "chrome":
              System.setProperty("webdriver.chrome.driver", ConfigParser.getChromeDriver());
              System.out.println("ChromeDriver on: " + ConfigParser.getChromeDriver());
              createChromeDriver();
              break;
          case "ie":
              System.setProperty("webdriver.ie.driver", ConfigParser.getIEDriverServer());
              System.out.println("IEDriver on: " + ConfigParser.getIEDriverServer());
              createIEDriver();
              break;
          default:
              LOGGER.warning("Unsupported Browser: " + browser);
              break;
      }
  }
  private static void createFirefoxDriver() {`enter code here`
      setCapability("firefox");
      GeckoDriverService.Builder builder = new GeckoDriverService.Builder();
      GeckoDriverService service = builder.build();
      FirefoxOptions options = new FirefoxOptions(capabilities);
      ProfilesIni profile = new ProfilesIni();
      FirefoxProfile myProfile = profile.getProfile("default");
      myProfile.setPreference("dom.disable_beforeunload", true);
      options.setProfile(myProfile);
      driver = new FirefoxDriver(service, options);
  }
  
  private static void createChromeDriver() {
      setCapability("chrome");
      ChromeDriverService.Builder builder = new ChromeDriverService.Builder();
      ChromeDriverService service = builder.build();
      ChromeOptions options = new ChromeOptions();
      options.merge(capabilities);
      driver = new ChromeDriver(service, options);
  }
  
  private static void createIEDriver() {
      setCapability("ie");
      InternetExplorerDriverService.Builder builder = new InternetExplorerDriverService.Builder();
      InternetExplorerDriverService service = builder.build();
      InternetExplorerOptions options = new InternetExplorerOptions(capabilities);
      driver = new InternetExplorerDriver(service, options);
      CommonJS.executeScript(driver, "window.localStorage.clear();");
      CommonJS.executeScript(driver, "window.sessionStorage.clear();");
  }
  
  private static void setCapability(String browser) {
      capabilities = new DesiredCapabilities();
      capabilities.setCapability(CapabilityType.ForSeleniumServer.ENSURING_CLEAN_SESSION, true);
      capabilities.setCapability(CapabilityType.ELEMENT_SCROLL_BEHAVIOR, true);
      if (browser.equalsIgnoreCase("ie")) {
          capabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
          capabilities.setCapability(InternetExplorerDriver.IGNORE_ZOOM_SETTING, true);
          capabilities.setCapability(InternetExplorerDriver.REQUIRE_WINDOW_FOCUS, true);
          capabilities.setCapability(InternetExplorerDriver.INITIAL_BROWSER_URL, ConfigParser.getAppUrl());
      } else if (browser.equalsIgnoreCase("chrome")) {
          ChromeOptions options = new ChromeOptions();
          options.addArguments("chrome.switches","--disable-extensions");
          capabilities.setCapability(ChromeOptions.CAPABILITY, options);
      }
  }
  </code></pre>
  
  <p>Sorry for all the code, but I'm sure I'll be asked about those details, hence my putting there.
  Long story short: </p>
  
  <ul>
  <li><p>This only happens with HTTPS URL's</p></li>
  <li><p>Non HTTPS URL's work just fine</p></li>
  <li><p>It's not an SSL certificate issue otherwise I would have seen it on the screen "This connection is untrusted".</p></li>
  </ul>