简体   繁体   English

GEB找到第一个可见元素

[英]GEB find first visible element

I have got some hidden buttons on the page. 我在页面上有一些隐藏的按钮。 When I click on text input, one of these buttons shows on the page. 当我单击文本输入时,页面上会显示其中一个按钮。 Before: 之前:

<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>

After click on second input: 点击第二个输入后:

<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>

So I try to interact with second button by next selectors in my test: 所以我尝试在我的测试中通过下一个选择器与第二个按钮进行交互:

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

but I have next error: 但我有下一个错误:

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

If I write: 如果我写:

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

it works, but I need to work with one first visible button on the page. 它有效,但我需要使用页面上的第一个可见按钮。 What is wrong? 怎么了?

Unfortunately there is no css selector to find visible elements but you can use displayed property of Navigator and its findAll() method to find the button that is visible: 遗憾的是,找不到可见元素的css选择器,但您可以使用Navigator displayed属性及其findAll()方法来查找可见的按钮:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM