问题描述
我有以下情况:
<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>
我需要从中选择货币.我正在尝试以下操作,但没有办法:
I need to select the currencies from it. I was trying the following thing but no way:
assert $('UL.select2-results LI.select2-results-dept-0.select2-result.select2-result-selectable', 0..2)*.text() == ["GBP", "KPW", "USD"]
即使我无法处理这个问题:
Even I could not handle this one:
assert $('UL.select2-results LI.select2-results-dept-0.select2-result.select2-result-selectable')*.size() == 3
尽管如此,我只能处理一个元素:
Though, I can handle a single element:
assert $('UL.select2-results').find("LI.select2-results-dept-0.select2-result.select2-result-selectable", 0).text() == "GBP"
任何帮助或建议对我来说都是非常有益的!谢谢!
Any help or suggestion would be really beneficial for me! Thanks!
推荐答案
我不知道为什么@Gabriel的答案不起作用!我知道0..3存在问题,因为它将是0..2!但是找到它最终没有起作用:
I don't know why @Gabriel's answer did not work! I know there was an issue with 0..3 as it would be 0..2! But instead of find it finally worked:
assert $('UL.select2-results LI.select2-results-dept-0.select2-result.select2-result-selectable span')*.text() == ["GBP", "KPW", "USD"]
我很想看看是否有人可以解释为什么索引+使用find + *不能针对这个特定问题一起工作,或者存在任何与逻辑语法相关的问题.
I would love to see if anyone can explain why indexing+using find+* did not work together for this particular problem or was there any logical syntax related problem.
这篇关于如何在GEB中选择内部元素的文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!