【发布时间】:2016-02-11 21:11:48
【问题描述】:
我有一个单击按钮的方法,但是,当它运行时,selenium 返回成功单击的结果,而实际上,实际上并未实际单击该按钮。如果我多次运行测试,偶尔,它会按预期被点击。我将我的测试框架设置为隐式等待大约 15 秒,我已经为此元素设置了显式等待,但仍然看到相同的问题。当我执行<element>.isDisplayed() 时,总是会找到该元素。我将 .click 放在一个 while 循环中以单击它几次,这在大多数情况下都有效,但是,有时测试仍然会失败。是否可以在单击按钮之前使用 if 语句检查元素是否实际显示?
我试过了:
if(!element.isDisplayed){
element.click
}
这是我遇到问题的按钮:
<button class="notkoButton listNew">
<div class="l6e iconAdd">New List</div>
</button>
这是我的方法:
public marketing_lists_page navigateToNewListPage() throws Throwable {
try {
int x = 0;
while(x < 5) {
newListBtn.click();
x++;
}
//newListPageHeader.isDisplayed();
} catch (NoSuchElementException e){
logs.errorDetails("Could not navigate to New List Page");
Assert.fail();
}
return this;
}
【问题讨论】:
-
你不应该这样做
if(!element.isDisplayed) { element.click };。
标签: java selenium testing selenium-webdriver automated-tests