Search code examples
testingcodeceptjs

How can I locate a parent of an element know by child value using CodeceptJS


basically I have the following:

<div class="container">
  <div class="title">title 1</div>
</div>
<div class="container">
  <div class="title">title 2</div>
</div>
<div class="container">
  <div class="title">title 3</div>
</div>

I want to locate the container that has "title 2" as title, without Xpath Please. I mean just css selectors and codeceptJS functions. Is it possible to do it?


Solution

  • You can do:

    locate(".container").withChild(".title").withText("title 2")
    

    See the locator builder documentation for more info.