다음은 몇 가지 옵션입니다.
우리가 HTML과 같은 것으로 가정 해 봅시다 :
<ul>
<li class="cellGridGameStandard">
Element 1
</li>
<li class="cellGridGameStandard ownAlready">
Element 2
</li>
<li class="cellGridGameStandard notEligible">
Element 3
</li>
<li class="cellGridGameStandard">
Element 4
</li>
</ul>
첫 번째와 네 번째 리 요소가 지정된 기준과 일치.
matching = browser.lis(:class => 'cellGridGameStandard')
.find_all { |li|
['ownAlready', 'notEligible'].none? {
|class_name| li.class_name.split.include? class_name
}
}
p matching.collect(&:text)
#=> ["Element 1", "Element 4"]
쓰기 쉽게하지만 때로는 읽기 어려워 간주 또 다른 옵션은, CSS를 로케이터를 사용하는 것입니다
하나의 옵션은 ownAlready
또는 notEligible
클래스를하지 않아도 문양을 확인하는 것입니다 :
matching = browser.elements(:css => 'li.cellGridGameStandard:not(.ownAlready):not(.notEligible)')
p matching.collect(&:text)
#=> ["Element 1", "Element 4"]
감사합니다; 내가 필요한 것. 나는 css locator 옵션을 사용했다. 멋지고 간결합니다. – bigtunacan