Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mink selectors: any way to get the element in base of the content inside?

Tags:

symfony

bdd

for example, given the text of a link, retrieve the hole link element.

I tried this:

$page = $this->getSession()->getPage();
$page->find('content', 'Italiano');

But it says:

Selector "content" is not registered.

EDIT: after check the links of the everzet's answers I have this:

$el = $page->find('named', array(
        'content', $this->getMainContext()->getSession()->getSelectorsHandler()->xpathLiteral('Pound')));

$el->click();

but I'm getting this error about click() function:

When I choose "Pound sterling" #

MyFirm\FrontendBundle\Features\Context\CurrencyControllerContext::iChoose()

error:_click(_byXPath("(//html/./descendant-or-self::*[contains(normalize-space(.), 'Pound')])[1]")) TypeError: parent.tagName is undefined ([object HTMLHtmlElement],"A",1)@http://myfirm.localhost/s/spr/concat.js:3286 ([object HTMLHtmlElement],"A")@http://myfirm.localhost/s/spr/concat.js:3762 ([object HTMLHtmlElement])@http://myfirm.localhost/s/spr/concat.js:331 ([object HTMLHtmlElement],false,false,(void 0))@http://myfirm.localhost/s/spr/concat.js:708 ([object HTMLHtmlElement])@http://myfirm.localhost/s/spr/concat.js:478 ()@http://myfirm.localhost/s/spr/concat.js:3016 ()@http://myfirm.localhost/s/spr/concat.js:3016 @http://myfirm.localhost/s/spr/concat.js:2822

  <a

href='/s/dyn/Log_getBrowserScript?href=null&n=3286'>Click for browser script

This is the beginning of the output of var_dump($el):

object(Behat\Mink\Element\NodeElement)#438 (2) {
  ["xpath":"Behat\Mink\Element\NodeElement":private]=>
  string(74) "(//html/./descendant-or-self::*[contains(normalize-space(.), 'Pound')])[1]"

And the output of $el->getTagName() is 'html'.

Is that because I'm trying to click something that is not an element but just content? In that case, any way to get the element from the content?

like image 482
ziiweb Avatar asked Sep 30 '11 18:09

ziiweb


2 Answers

You should use:

$page = $this->getSession()->getPage();
$page->find('css', 'Italiano');

This is using the CSS selectors, and it works like a magic! But make sure 'Italiano' refers to an element on the page (I would use '#Italiano' if it's an ID).

You can read the traversing pages documentation here.

like image 133
vijay pujar Avatar answered Sep 22 '22 23:09

vijay pujar


Don't use content selector. Because in almost any case it will provide results, that you don't expect. For example, when you're doing content(Pound), you're expecting that it'll return you an element, that contains this text. The reality is, every parent element of target one is containing your "Pound" text, including <html/>. That's why you get <html/> at the end ;-)

Minks selectors are well-explained in the manual:

  • http://mink.behat.org
like image 45
everzet Avatar answered Sep 24 '22 23:09

everzet