Xpath // Trap
I am trying to loacte a attr element in a label context using capybara. The html looks like:
|
|
And I use the code like:
|
|
As usual, I’m pretty sure that the find will work like:
|
|
the find search the xpath in label context and find it.
Quite easy but I’m wrong.
In XPath the expression // means something very specific, and it might not be what you think.
Contrary to common belief, // means
As an example:
|
|
You might expect this to find all script tags in the body,
but actually, it finds all script tags in the entire document,
not only those in the body! What you’re looking for is the .// expression which means “any descendant of the current node”:
|
|
The same thing goes for within:
|
|
You can refer to capybara document
And also there is a great post: Using “//“ And “.//“ Expressions In XPath XML Search Directives In ColdFusion