title: Cannot automate signing in to Azure Active Directory using Selenium WebDriver
body: <p>I'm trying to test logging in to our web application using Azure AD but the click action on the Sign In button doesn't seem to register. Here's the code:</p>
  
  <pre><code>namespace WebApp.Tests
  {
      using System;
      using System.IO;
      using System.Threading;
      using FluentAssertions;
      using Microsoft.VisualStudio.TestTools.UnitTesting;
      using OpenQA.Selenium;
      using OpenQA.Selenium.IE;
      using OpenQA.Selenium.Remote;
      using OpenQA.Selenium.Support.UI;
  
      [TestClass]
      public class LoginTests
      {
          [TestMethod]
          public void CanLogin()
          {
              string internetExplorerDriverServerDirectory = Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory);
              IWebDriver driver = new InternetExplorerDriver(internetExplorerDriverServerDirectory)
              {
                  Url = "https://localhost:44399"
              };
  
              try
              {
                  driver.Manage().Cookies.DeleteAllCookies();
  
                  WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(15));
                  wait.Until(d =&gt; d.FindElement(By.Id("logonIdentifier")));
  
                  driver.FindElement(By.Id("logonIdentifier")).SendKeys("username");
                  driver.FindElement(By.Id("password")).SendKeys("password");   
                  driver.FindElement(By.Id("next")).Click();
  
                  wait = new WebDriverWait(driver, TimeSpan.FromSeconds(5));
                  wait.Until(d =&gt; d.FindElement(By.ClassName("logo_title")));
  
                  driver.FindElement(By.ClassName("logo_title")).Text.Should().Contain("HELLO!");
              }
              finally
              {
                  driver.Close();
                  driver.Quit();
                  driver.Dispose();
                  driver = null;
              }
          }
      }
  }
  </code></pre>
  
  <p>Here's the relevant bits of HTML:</p>
  
  <pre><code>&lt;div class="entry"&gt;
      &lt;div class="entry-item"&gt;
          &lt;label for="logonIdentifier"&gt;Email Address&lt;/label&gt;
          &lt;div class="error itemLevel" aria-hidden="true" style="display: none;"&gt;
              &lt;p role="alert"&gt;&lt;/p&gt;
          &lt;/div&gt;
          &lt;input type="email" id="logonIdentifier" name="Username or email address" pattern="^[a-zA-Z0-9.!#$%&amp;amp;’'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$" placeholder="Email Address" value="" tabindex="1" autocomplete="off"&gt;
      &lt;/div&gt;
      &lt;div class="entry-item"&gt;
          &lt;div class="password-label"&gt;
              &lt;label for="password"&gt;Password&lt;/label&gt;
                  &lt;a id="forgotPassword" tabindex="2" href="/redacted"&gt;Forgot your password?&lt;/a&gt;
          &lt;/div&gt;
          &lt;div class="error itemLevel" aria-hidden="true" style="display: none;"&gt;
              &lt;p role="alert"&gt;&lt;/p&gt;
          &lt;/div&gt;
          &lt;input type="password" id="password" name="Password" placeholder="Password" tabindex="1" autocomplete="off"&gt;
      &lt;/div&gt;
      &lt;div class="working"&gt;&lt;/div&gt;
      &lt;div class="buttons"&gt;
          &lt;button id="next" tabindex="1"&gt;Sign in&lt;/button&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>It all looks OK in the browser: the username and password fields are filled in, the button looks like it gets clicked (the little "working" icon appears briefly above it) but nothing happens.</p>
  
  <ul>
  <li>I've tried a longer wait (up to 30 seconds) for the home page to
  appear after clicking the Sign In button.</li>
  </ul>
  
  <p><code>wait = new WebDriverWait(driver, TimeSpan.FromSeconds(30));</code></p>
  
  <ul>
  <li>I've tried sending an <code>Enter</code> key while in the form instead of clicking
  the button.</li>
  </ul>
  
  <p><code>driver.FindElement(By.Id("password")).SendKeys(Keys.Enter);</code></p>
  
  <ul>
  <li>I've tried executing some JavaScript to call the button click action.</li>
  </ul>
  
  <p><code>IJavaScriptExecutor jse = (IJavaScriptExecutor)driver;</code>
  <code>jse.ExecuteScript("document.getElementById('next').click();");</code></p>
  
  <ul>
  <li>I've tried using the Chrome and Firefox drivers.</li>
  <li>I've tried on both the local development version and the hosted test    environment.</li>
  </ul>
  
  <p>Nothing so far has worked. There are no error/validation messages shown in the browser during the process.</p>
  
  <p>I'm at a bit of a loss with this one.</p>
  
  <p>Thanks,
  Stuart.</p>