Mink icon indicating copy to clipboard operation
Mink copied to clipboard

XPathManupulator parentesis handling bug

Open aik099 opened this issue 11 years ago • 4 comments

Consider following input:

  • prefix: descendant-or-self::*[@id = 'checkbox-with-preceding-label']
  • xpath: (//label[@for = 'checkbox-with-preceding-label'])[1]

I expect result to be descendant-or-self::*[@id = 'checkbox-with-preceding-label']/(//label[@for = 'checkbox-with-preceding-label'])[1] (both prefix and xpath combined using /).

In reality this produced this xpath: (descendant-or-self::*[@id = 'checkbox-with-preceding-label']//label[@for = 'checkbox-with-preceding-label'])[1] (the prefix is injected into parenthesis and produces xpath that doesn't match what's expected).

I'm using parentheses in xpath to specify which of found elements I want to get. It as well can be 5th element, so using find instead of findAll method isn't a viable solution.

P.S. I'm trying to find matching label by for attribute across the document, but I start with checkbox xpath, that I can't change.

aik099 avatar Aug 16 '14 08:08 aik099

Right now I've changed xpath to look like (preceding::label[@for = 'checkbox-with-preceding-label'] | following::label[@for = 'checkbox-with-preceding-label'])[1] and it works. Maybe there is a better way.

aik099 avatar Aug 16 '14 08:08 aik099

The app I'm used to evaluate that XPATH is called Phathology (http://celestialteapot.com/pathology/) and it works in there. However it doesn't any other XPATH evaluator I've tried. I guess using () in between of / is forbidden in XPATH.

aik099 avatar Aug 17 '14 19:08 aik099

yep, it is forbidden (which is why prepending a prefix is so complex).

The case of (//label[@for = 'checkbox-with-preceding-label'])[1] is indeed not covered in the XPathManipulator currently (it is very complex as it might require altering the parent, and none of the Mink selectors will produce such XPath)

stof avatar Aug 18 '14 09:08 stof

@stof , can you suggest alternative xpath for locating checkbox/radio label, when I'm already on it other then in https://github.com/minkphp/Mink/issues/593#issuecomment-52387653 comment?

aik099 avatar Aug 18 '14 09:08 aik099