testing - GEB 找到第一个可见元素

标签 testing groovy automated-tests geb

我在页面上有一些隐藏的按钮。当我单击文本输入时,这些按钮之一会显示在页面上。之前:

<div field='login'>
    <input type="text"> 
    <button class="submit" style="display: none">Save</button>
</div>

<div field='name'>
    <input type="text"> 
    <button class="submit" style="display: none">Save</button>
</div>

点击第二个输入后:

<div field='login'>
    <input type="text"> 
    <button class="submit" style="display: none">Save</button>
</div>

<div field='name'>
    <input type="text"> 
    <button class="submit">Save</button>
</div>

所以我尝试在我的测试中通过下一个选择器与第二个按钮进行交互:

static content = {
    submitButton { $("button.submit") }
}

但我有下一个错误:

isorg.openqa.selenium.ElementNotVisibleException: Element is not currently visible and so may not be interacted with

如果我写:

static content = {
    submitButton { $("button.submit", 1) }
}

它有效,但我需要使用页面上的第一个可见按钮。怎么了?

最佳答案

不幸的是,没有用于查找可见元素的 css 选择器,但您可以使用 displayed property Navigator 及其 findAll() method找到可见的按钮:

static content = {
    submitButton { $("button.submit").findAll { it.displayed } }
}

关于testing - GEB 找到第一个可见元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26359178/

相关文章:

php - Laravel:在自定义 Route::model 绑定(bind)中使用模拟实例

java - 从 Groovy 测试用例模拟 Java 类

html - 使用 WATIR 检索 <TD> 文本

linux - Eclipse+Solex 的 HTTP 记录/回放替代方案

java - ExpectedConditions.or 函数未按预期工作

visual-studio - 与 Visual Studio 2008 提供的测试库相比,其他测试库有什么优势?

testing - 如何用较少的计算能力测试应用程序和网站?

testing - 转到类型错误 : struct does not implement interface

java - 将 Stream 转换为字符串 Java/Groovy

forms - Grails表单提交使用字符串填充Integer字段