It seemed Capybara lacked a simple way to get an element's parent ( http://stackoverflow.com/questions/4861863/how-to-get-parent-node-in-capybara ) so I've added support for this.
Adding support for getting an element's parent
Just do find(:xpath, '..'). No need to expose these kinds of traversal methods in Capybara.
@jnicklas is there a way to do that but lazy find the body? I'm trying to get back to the body from inside a within, so that I can check it loaded a popup....
@jnicklas looks like find(:xpath, '//body') works :D
How is this not a useful addition? Not everyone is comfortable with xpath... I'd prefer to have a jquery like navigation available. Even more useful would be something like http://api.jquery.com/closest/
Sorry for dragging an old issue up.
I don't agree with jnicklas. capybaras purpose is to allow us to test against a page, which may include finding an element then traversing to another element to check something. It may be slightly less common than click "somebutton" but its still valuable.
+1 I would like this feature too, even if it's just syntactic sugar
this doesn't work if you chain it... seems like you can't call subsequent finds on the returned node.
NoMethodError: undefined method `' for #Capybara::Document
When the hell did we merge this? This is definitely, definitely not the right way to implement that method, no idea how that got in there.
I don't think we ever merged it. It's part of #505, and GitHub's UI is just confusing.
I'm not against this feature, though it is just syntactic sugar, so I find it a bit redundant. This pull request though is just completely wrong. So if someone wants this, please send a better pull request.
What does Capybara::Node::Base#parent attribute currently do? It seems to be always returning Capybara::Document instead of the actual tag's parent.
@janko-m Its the context for the find which located the current element.
@janko-m Base#parent is internally used to get an ancestor using which the current element was located. For example in:
el = find('a')
el.find('b').parent # => returns el