I'd like to find closest parent of an html element in cucumber. just like the .closest() function of jQuery does.
this is my (pseudo) code:
aspect = find('.dropdown li:contains('+selector+')')
dropdown = aspect.closest('.dropdown') #<-- the closest() function does not exist
if not aspect.hasClass('.selected')
dropdown.click
sleep 1
aspect.click
end
can anybody tell me how to accomplish this using Capybara?
Cheers!
Manuel
This is not a universal solution, but if all you want to do is click the element, I would suggest using jQuery directly:
page.execute_script('$(...).closest(...).click()')
Other than that, Capybara does not have a .closest method, but in many cases, being more creative with selectors (possibly using XPath) might do the trick.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With