Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding support for getting an element's parent #505

Closed
wants to merge 1 commit into from
Closed

Adding support for getting an element's parent #505

wants to merge 1 commit into from

Conversation

andyw8
Copy link

@andyw8 andyw8 commented Sep 24, 2011

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.

@jnicklas
Copy link
Collaborator

Just do find(:xpath, '..'). No need to expose these kinds of traversal methods in Capybara.

@jnicklas jnicklas closed this Nov 15, 2011
@cj
Copy link

cj commented Mar 7, 2012

@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....

@cj
Copy link

cj commented Mar 7, 2012

@jnicklas looks like find(:xpath, '//body') works :D

@dgm
Copy link

dgm commented Jun 24, 2012

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/

@mikebaldry
Copy link

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.

@dfl
Copy link

dfl commented Oct 9, 2012

+1 I would like this feature too, even if it's just syntactic sugar

@jnicklas
Copy link
Collaborator

jnicklas commented Oct 9, 2012

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.

@janko
Copy link

janko commented Apr 7, 2015

What does Capybara::Node::Base#parent attribute currently do? It seems to be always returning Capybara::Document instead of the actual tag's parent.

@twalpole
Copy link
Member

twalpole commented Apr 7, 2015

@janko-m Its the context for the find which located the current element.

@abotalov
Copy link
Collaborator

abotalov commented Apr 7, 2015

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants