c# - Selenium 测试用于 Azure Active Directory 登录的 Edge webdriver 时元素被遮挡 登录您的帐户页面

标签 c# selenium-webdriver integration-testing coded-ui-tests azure-active-directory

我正在使用 Selenium 进行集成测试。部分测试是 Microsoft Azure Active Directory uses 的登录过程

使用 InternetExplorerWebDriver 时测试通过,但使用 EdgeWebDriver 时失败并出现错误:

Element is obscured

相关部分代码:

var wait = new WebDriverWait(webDriver, TimeSpan.FromSeconds(10));
webDriver.Url = Settings.UrlHome();

var signInElement = webDriver.FindElement(By.Id("SignInLink"));
signInElement.Click();      

wait.Until(ExpectedConditions.ElementToBeClickable(By.Id("my_login_name")));
var loginLogoMicrosoft = webDriver.FindElement(By.Id("my_login_name"));

loginLogoMicrosoft.Click();

错误发生在执行最后一个Click()时。我尝试了其他几个元素,但都没有用。还“检查元素”以确定哪些元素收到点击在代码中实现时会出现此错误。

如何使 Microsoft Azure Active Directory 登录过程成为我的 Selenium 测试的一部分?

发现同类问题here .

最佳答案

我使用以下代码填写 Azure AD 登录表单。需要注意的是,当您填写用户名字段时,“登录”按钮将被禁用,直到在后台完成某些 ajax 操作。诀窍是等到页面上出现没有此类的登录按钮。

private void SubmitLoginForm()
{
    var useAnotherAccount = Driver.FindElements(By.ClassName("use_another_account")).FirstOrDefault();

    if (useAnotherAccount != null)
    {
        useAnotherAccount.Click();
    }

    var loginInput = Driver.FindElements(By.Id(Site.Login.UserNameInput)).FirstOrDefault();

    if (loginInput != null)
    {
        loginInput.SendKeys(TestingData.UserName);
        loginInput.SendKeys(Keys.Tab);
    }

    var passwordInput = Driver.FindElements(By.Id(Site.Login.PasswordInput)).FirstOrDefault();

    if (passwordInput != null)
    {
        passwordInput.Clear();
        passwordInput.SendKeys(TestingData.PassWord);
        passwordInput.SendKeys(Keys.Enter);
    }

    var wait = new WebDriverWait(Driver, TimeSpan.FromSeconds(5));
    wait.Until(f => f.FindElement(By.CssSelector("#cred_sign_in_button:not(.disabled_button")));

    var loginButton = Driver.FindElements(By.Id(Site.Login.SigninButton)).FirstOrDefault();

    if (loginButton != null)
    {
        loginButton.Click();
        return;
    }

    throw new InvalidOperationException("Could not click the login button");
}

关于c# - Selenium 测试用于 Azure Active Directory 登录的 Edge webdriver 时元素被遮挡 登录您的帐户页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40657575/

相关文章:

java - 无法与 Instagram 登录字段交互

c# - Respawn 没有重置我的 SQL Server 数据库

c# - TimeZoneInfo SupportsDaylightSavingTime 没有返回我期望的结果,为什么?

c# - 适用于 Windows Phone 的 Facebook SDK : InvalidOperationException: Operation is not valid due to the current state of the object

javascript - 无法再在 Chrome 中打开和关闭标签页

ruby-on-rails - 如何从 Rails 集成测试访问 session ?

java - 使用 maven : run jar before tests and terminate after 进行集成测试

c# - 自定义 Web 服务器控件在调用 Web 服务时失败

c# - Azure 不支持外语文件格式名称下载

python - 如何正确停止 phantomjs 执行