【发布时间】:2013-12-22 20:53:03
【问题描述】:
我正在使用 Selenium 2.37.1 和 Chrome 驱动程序 2.7(在 Ubuntu 13.10 上使用 Chrome 31.0.1650.63)为我的基于 Java/Spring/Boostrap 的网站编写一些测试。
测试单击登录文本,然后尝试在单击提交按钮之前将提供的用户名和密码输入表单。我已经分解了元素的发现并调用了 sendKeys 来确定 Selenium 的后续位置(它在 username.sendKeys 上)
public void login(final String user) {
webDriver.findElement(By.id("login")).click();
final WebElement loginForm = webDriver.findElement(By.id("loginForm"));
final WebElement username = loginForm.findElement(By.id("username"));
username.sendKeys(user);
final WebElement password = loginForm.findElement(By.id("password"));
password.sendKeys(dslConstants.PASSWORD);
loginForm.submit();
}
用户名找到成功,但是当我运行username.isDisplayed()的时候,它实际上是被显示出来的。
我假设这与 Selenium 无法正确处理 Bootstrap 弹出框有关,并且想知道是否有人对此有任何修复?
提前致谢。
编辑:
loginForm.isDisplayed() 在调试时可见时也会返回 false。我也试过加一个等待条件,也没有解决问题。
final WebDriverWait wait = new WebDriverWait(webDriver, TIME_OUT_IN_SECONDS);
wait.until(ExpectedConditions.visibilityOf(webDriver.findElement(By.id("username"))));
编辑2: 这是页面的 HTML/JSTL 方面。
<div class="navbar">
<ul class="nav navbar-nav">
<li><a href="/">Home</a></li>
<sec:authorize ifAnyGranted="ROLE_ANONYMOUS">
<div class="hide" id="login-popover">
<form role="form" id="loginForm" method="post" action="j_spring_security_check">
<div class="control-group">
<label class="control-label" for="username">Username</label>
<div class="controls">
<input type="text" id="username" class="form-control" name="j_username" />
</div>
</div>
<div class="control-group">
<label class="control-label" for="password">Password</label>
<div class="controls">
<input type="password" id="password" class="form-control" name="j_password" />
</div>
</div>
<div class="control-group">
<div class="controls">
<button class="btn btn-primary" type="submit">Login</button>
</div>
</div>
</form>
</div>
<li><a href="#" id="login">Login</a></li>
<li><a href="/accounts/register">Register</a></li>
</sec:authorize>
</ul>
</div>
编辑 3: 使用 FireFox 25 时也会出现这种情况
【问题讨论】:
-
我有两个问题:您使用的是哪种浏览器?您是否尝试调试此代码?
-
我正在使用 Chrome 网络驱动程序,并且我已经调试了代码。我想附上的截图是在执行 username.sendKeys(user) 之前显示正在显示的登录表单
-
您使用的是哪个版本的 chrome?
-
你能附上html的部分吗?还需要 chromedriver 的版本。
-
版本 31.0.1650.63 我应该补充一点,我正在 Ubuntu 13.10 上通过 IntelliJ 12 运行网站和测试
标签: java twitter-bootstrap selenium acceptance-testing