我正在使用 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/