【发布时间】:2021-04-07 01:32:20
【问题描述】:
我是自动化新手,正在尝试测试一次失败的登录。输入错误密码时,网站上会显示错误弹出窗口。我正在尝试编写测试以确认显示错误文本。
代码试验:
@Test
public void IncorrectPasswordMessage() {
boolean b=driver.findElement(By.xpath("//*[@id=\"errors\"]/h2")).isDisplayed();
Assert.assertTrue(b);
}
HTML 如下。如何更改我的脚本以确认嵌套文本“有以下错误。” 显示在网页上?
<form id="login_form" action="/cs/form/customer-login" method="AJAX" class="cforms pad-top1 span6">
<!--|cid=1400679170853|type=Forms_P|-->
<div id="errors" style="">
<h2>There are the following errors.</h2>
<ul><li>The number and password you have entered do not match. Please enter it again.</li></ul>
</div>
<input type="hidden" name="_form_url" value="">
<input type="hidden" name="_success_url" value="">
<input type="hidden" name="_failure_url" value="">
</form>
【问题讨论】:
-
根据您的
Assert.assertTrue(),我已将javascript标签替换为java标签。如果更改看起来不错,请告诉我。
标签: java selenium xpath css-selectors webdriverwait