html - 如何在GEB中选择内部元素的文本?

标签 html css grails spock geb

我有以下场景:

<div>
    <ul class="select2-results" style="width: 400px;">
        <li class="select2-results-dept-0 select2-result select2-result-selectable">
            <div class="select2-result-label">
                <span id="12345" class="null">
                    GBP
                </span>
            </div>
        </li>
        <li class="select2-results-dept-0 select2-result select2-result-selectable">
            <div class="select2-result-label">
                <span id="45678" class="null">
                    KPW
                </span>
            </div>
        </li>
        <li class="select2-results-dept-0 select2-result select2-result-selectable">
            <div class="select2-result-label">
                <span id="12345" class="null">
                    USD
                </span>
            </div>
        </li>
    </ul>
</div>

我需要从中选择货币。我正在尝试以下操作,但没有办法:

assert $('UL.select2-results LI.select2-results-dept-0.select2-result.select2-result-selectable', 0..2)*.text() == ["GBP", "KPW", "USD"]

连我都搞不定:

assert $('UL.select2-results LI.select2-results-dept-0.select2-result.select2-result-selectable')*.size() == 3

不过,我可以处理单个元素:

assert $('UL.select2-results').find("LI.select2-results-dept-0.select2-result.select2-result-selectable", 0).text() == "GBP"

任何帮助或建议对我来说都是非常有益的!谢谢!

最佳答案

仅通过观察您的示例,您得到的是 3 个 DIV。看起来您需要更深入一点,在星号之前添加 .find('span')

assert $(
   'UL.select2-results LI.select2-results-dept-0.select2-result.select2-result-selectable',
    0..3)*.text() == ["GBP", "KPW", "USD"]

成为

assert $(
   'UL.select2-results LI.select2-results-dept-0.select2-result.select2-result-selectable',
    0..3).find('span')*.text() == ["GBP", "KPW", "USD"]

关于html - 如何在GEB中选择内部元素的文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22027890/

相关文章:

javascript - 当它得到位置固定时缩小 tr 宽度

css - 我如何知道何时使用 -webkit-、-moz、-ms-、-o- 等?

grails - 通过metaClass在Grails电子邮件插件中添加/修改密件抄送

http - 在grails gsp中访问http请求参数

caching - Grails/Tomcat : Avoiding denial of service attacks

javascript - 视频未在 IE 和 Chrome 中显示

php - 如果选择标签的选项值不是特定值,我如何设置默认值?

html - 有序列表编号和标签未对齐

javascript - OpenShift 找不到 css 和 js 文件

javascript - 切换 jquery 容器内的链接不起作用