0

I have this html code:

<div id="directoryDropdown">
  <div>
    <div id="toclistitemID6">
      "5"
      ". &nbsp;"
      "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:

  1. //div[contains(text(),'Conclusion Page')] - doesn't find the element
  2. //div[contains(.,'Conclusion Page')] - finds 8 elements including all parent elements of this one
  3. //div[text()[contains(.,'Conclusion Page')]] - finds the parent element div id="directoryDropdown"
  4. //div[@id='directoryDropdown']/child::div/child::div[contains(text(),'Conclusion Page')] - 0 elements found
  5. //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>
Pockemon
  • 13
  • 5

1 Answers1

-1

Try this:

//div[contains(child::text(), "Conclusion Page")]
komov.r
  • 54
  • 3