private void RunAutomatedDeviceCodeFlow(DeviceCodeResult deviceCodeResult, LabUser user, bool isAdfs = false) { try { var fields = new UserInformationFieldIds(user); Trace.WriteLine("Browser is open. Navigating to the Device Code url and entering the code"); string codeId = isAdfs ? "userCodeInput" : "code"; string continueId = isAdfs ? "confirmationButton" : "continueBtn"; _seleniumDriver.Navigate().GoToUrl(deviceCodeResult.VerificationUrl); _seleniumDriver // Device Code Flow web ui is undergoing A/B testing and is sometimes different - use 2 IDs .FindElement(SeleniumExtensions.ByIds("otc", codeId)) .SendKeys(deviceCodeResult.UserCode); IWebElement continueBtn = _seleniumDriver.WaitForElementToBeVisibleAndEnabled( SeleniumExtensions.ByIds(fields.AADSignInButtonId, continueId)); continueBtn?.Click(); _seleniumDriver.PerformLogin(user, Prompt.SelectAccount, isAdfs); Trace.WriteLine("Authentication complete"); } catch (Exception ex) { Trace.WriteLine("Browser automation failed " + ex); _seleniumDriver.SaveScreenshot(TestContext); throw; } }