No doubt that this is extremely basic, but it just won't "click" for me, despite the research that I've done so far. Given the following two HTML examples:
Example 1
<div _ngcontent-c35="" class="row facet-container ng-star-inserted">
<div _ngcontent-c35="" class="searchresult-header">
Locatie
</div>
</div>
Example 2
<div _ngcontent-c42="" class="row facet-panel ng-star-inserted">
<div _ngcontent-c42="" class="facet-panel-header brand-pointer" data-target="#ft5" data-toggle="collapse">
<span _ngcontent-c42="" class="icon-plus ng-star-inserted" data-target="#ft5" data-toggle="collapse">
</span>
Locatie
</div>
<div _ngcontent-c42="" class="collapse" id="ft5">
</div>
</div>
Now I have the following piece of xpath:
//div[.//div[normalize-space(text())='Locatie']]
According to other questions and websites about xpath, text() selects text nodes directly descending from the node we're searching on. Therefore, in example #1, I expect to retrieve the first child "div" element. This happens correctly: no issues there.
I expect the same result in example #2. However, this is not the case: apparently the "span" element disrupts this specific search. When I manually remove it, I succesfully retrieve the required "div" element. Why is the search disrupted? The text should still be a direct child of the div element, no matter if the span element is there or not.
TLDR: Why does the "span" element prevent me from finding the second "div" element in example #2?