I am trying to look for a node based on text that is available on a child/grandchild node of it's immediate brother. The HTML looks something like this:
<div>
<div class="searchedDivClass" id="DynamicId1">
</div>
<div class="classType1">
//<h1> some text </h1>
</div>
//
<div class="searchedDivClass">
</div>
<div class="classType2">
//<p> some other text </p>
</div>
</div>
As you can see the searched text can be in any type of tag, but it is always part of the text.
I thought that the following XPath would work:
drive.FindElementsByXPath("//div[following-sibling::div[1][//*[contains(text(),'some text')]] and contains(@class,'searchedDivClass')]")
Broken down into pieces:
//div[contains(@class,'searchedDivClass')]
Makes sure it returns the right level of div that I am looking for, not higher up or lower down in the tree.
//div[following-sibling::div[1][//*[contains(text(),'some text')]]
Looks for the first sibling of the div found above. Inside this sibling, it looks for an element that contains the text we are looking for.
However, when I look at how many elements it return, it is actually greater than the number of elements that have the 'searchedDivClass'.
Note that removing the //*[contains(text(),'some text')]
At least returns the number of elements with the searched class.
Finally, that last XPath on it's own correctly returns the element containing the text.
Any idea, or recommendations?