空手道:检查一个元素是否位于另一个元素下方

问题描述 投票:0回答:1

我有这个html:

<div>
  <div>
    <select attribute = "first select"> 
      <option1></option>
      <option1></option>
    </select>
  </div>
<div>
<div>
  <div>
    <select attribute = "second select"> 
      <option1></option>
      <option1></option>
    </select>
  </div>
<div>

我可以检查空手道中的“第二个选择”是否低于“第一个选择”吗?

select parent-child karate
1个回答
0
投票

假设您的 HTML 是:

<div>
  <div>
    <select class="first select"> 
      <option></option>
      <option></option>
    </select>
  </div>
</div>
<div>
  <div>
    <select class="second select"> 
      <option></option>
      <option></option>
    </select>
  </div>
</div>  

然后这就会起作用:

* def data = scriptAll('select', "_.getAttribute('class')")
* print 'data:', data
* def firstIndex = data.findIndex(x => x.includes('first'))
* def secondIndex = data.findIndex(x => x.includes('second'))
* print 'firstIndex:', firstIndex, 'secondIndex:', secondIndex 
* assert firstIndex < secondIndex

我个人不喜欢这类测试。但你明白了,如果你将 HTML 转换为 JSON,那么你可以对其进行一些分析。

© www.soinside.com 2019 - 2024. All rights reserved.