xpath

How to get parent element by the contents of two child elements?


I have a list of events with the following contents:

<div class="all-ebents">
    <div class="sport-base-event">
        <span class="event-block-current-time__time--VEuoj">63:07</span>
        <span class="event-block-score">0:0</span></div>
    </div>

    <div class="sport-base-event">
        <span class="event-block-current-time__time--VEuoj">64:07</span>
        <span class="event-block-score">0:1</span></div>
    </div>

    <div class="sport-base-event">
        <span class="event-block-current-time__time--VEuoj">63:07</span>
        <span class="event-block-score">0:1</span></div>
    </div>
</div>

So far I have been able to get the event time value and count using the following code

//*[contains(@class, "event-block-current-time--")]::text() # get the time block
//*[contains(@class, "event-block-current-time--")]/following-sibling::div::text() # score block

What is the correct way to bypass these queries and get the parent element if the event time contains the value 63 and the score in the neighbouring element is 0:0?


Solution

  • place the predicates directly on the parent like this:

    //div[@class="sport-base-event"][span[contains(text(),"63")] and span[text()="0:0"]]
    

    This will get those divs with the class='sport-base-event' that have a span containing 63 and a span that has value 0:0