I have this html code:
<div id="directoryDropdown">
<div>
<div id="toclistitemID6">
"5"
". "
"Conclusion Page"
</div>
</div>
I need to select the div that has the "Conclusion Page" text. The id for the element is dynamic so I want to use the text but can't get the element to be found. I have tried the following xpath-s:
- //div[contains(text(),'Conclusion Page')] - doesn't find the element
- //div[contains(.,'Conclusion Page')] - finds 8 elements including all parent elements of this one
- //div[text()[contains(.,'Conclusion Page')]] - finds the parent element div id="directoryDropdown"
- //div[@id='directoryDropdown']/child::div/child::div[contains(text(),'Conclusion Page')] - 0 elements found
- //div[contains(text()1,"Conclusion Page")]/@id - 0 elements found
Can someone please recommend how to build the xpath to select this element? Or use any other locator that allows to select containing text for tests using Java/Selenium? (seems like CSS locators don't have this option)
UPDATE: After I try to copy the text from the element the object starts looking like that (without "5" ". ") and the element is found. So I guess the problem is that the actual text is inside of the object or is not the first text. Also posting whole html here:
<div id="directoryDropdown" xpath="1">
<div>
<div id="toclistitemID0"></div>
<div id="toclistitemID1" style="color: rgb(247, 181, 0);"></div>
<div id="toclistitemID2"></div>
<div id="toclistitemID5">Conclusion Page</div>
<div id="toclistitemID6"></div>
</div>
</div>