本文介绍了如何获得在Capybara的父节点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用许多jQuery插件,通常创建没有id或其他标识属性的DOM元素,并获得他们在Capybara(例如点击)的唯一方法是获取他们的邻居祖先)。但是我没有找到任何地方,Capybara支持这样的事情例如:

I'm working with many jQuery plugins, that often create DOM elements without id or other identification properties, and the only way to get them in Capybara (for clicking for example) - is to get their neighbor (another child of its ancestor) first. But I didn't find anywhere, does Capybara support such things for example:

find('#some_button').parent.fill_in "Name:", :with => name

推荐答案

我真的发现jamuraa的答案有帮助,但是完整的xpath给了我一个噩梦的字符串在我的情况下,所以我很高兴地利用了连接的水平Capybara的能力,让我混合css和xpath选择。您的示例将如下所示:

I really found jamuraa's answer helpful, but going for full xpath gave me a nightmare of a string in my case, so I happily made use of the ability to concatenate find's in Capybara, allowing me to mix css and xpath selection. Your example would then look like this:

find('#some_button').find(:xpath,".//..").fill_in "Name:", :with => name

Capybara 2.0更新 find xpath,// ..)将很可能导致模糊匹配错误。在这种情况下,改用 first(:xpath,.// ..)

Capybara 2.0 update: find(:xpath,".//..") will most likely result in an Ambiguous match error. In that case, use first(:xpath,".//..") instead.

这篇关于如何获得在Capybara的父节点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-19 23:29