How to find a text node element with Mink?
Asked Answered
L

1

10

I was wondering, i have this HTML :

<li>
  <span class="jqTransformRadioWrapper">
    <a rel="choices[choices]" class="jqTransformRadio jqTransformChecked" href = "#"></a>
    <input type="radio" id="choices_choices_5" value="5" name="choices[choices]" class="jqTransformHidden">
  </span>
  <label for = "choices_choices_5" style = "cursor: pointer;">My awesome test</label>
</li>

Some of you might recognize that the input has been jqTransformed

I was wondering how to click on the label named "My awesome test".

Right now, i do :

   $el = $this->getSession()->getPage()->find('css', 'ul li span.jqTransformRadioWrapper a');
   $el->click();

But it selects the first element. And i want to select them with their Name (and only) for this example it would be "My awesome test".

Thanks

Lacagnia answered 4/11, 2011 at 11:3 Comment(0)
L
13

Here's the answer :

$this->getSession()->getPage()->find('xpath', '//label[text()="My awesome test"]');
Lacagnia answered 8/11, 2011 at 14:49 Comment(1)
This will break when using ZombieJS as the driver: xpaths for the Zombie driver must not contain the character " or the server crashes (on <= 1.3.1, I don't know about 1.4.0+). Instead, use find('xpath', "//label[text()='My awesome test']");Hexapla

© 2022 - 2024 — McMap. All rights reserved.