Search code examples
dombehatsiblingsmink

How to find sibling element with behat/mink?


HTML:

<div id="my-id">
    <li class="list_element">
        <div class="my_class"></div>
        <a href=""></a>
    </li>
    <li class="list_element">
        <div class="another_class"></div>
        <a href=""></a>
    </li>
    <li class="list_element">
        <div class="class3"></div>
        <a href=""></a>
    </li>
</div>

What I want to do with behat/mink:

$page = $this->getSession()->getPage();
$selector = $page->find('css', "#my-id .my_class"); //here I need anchor element located near to .my_class div.

I don't know in which one .list_element .my_class div is. I know only anchor is next to .my_class element. Which selector should I use in the find() function?


Solution

  • Try one of these:

    #my-id .my_class ~ a
    
    #my-id .my_class + p
    
    #my-id .list_element a

    This is too basic question.Please see more here w3schools