I need to match elements with block
and result
until the first occurrence of the element with class block
but NOT result
.
XPath:
//div[contains(@class, 'result') and contains(@class ,'block')][following-sibling::div[contains(@class, 'block') and not(contains(@class,
'result'))]]
Example 1 (works in this case):
<div class="block result"></div> <!-- match this -->
<div class="block result"></div> <!-- match this -->
<div class="block"></div>
<div class="block result"></div> <!-- DONT match this -->
<div class="block result"></div> <!-- DONT match this -->
Example 2 (doesn't match anything here)
<div class="block result"></div> <!-- match this -->
<div class="block result"></div> <!-- match this -->
... so it doesn't matching anything in the second example. Can I make the following optional so it matches in both conditions?