如果该行中的另一个td与我的搜索查询匹配,我需要返回td的值。具体来说,我的名字是'属性,我想返回' id'属性(在同一行中找到)。以下是HTML的示例:
<tr class='desired_row'>
<td>
<input id="bulk_ids_" name="bulk_ids[]" type="checkbox" value="50" />
</td>
<td class='id_field integer_type' title='50'>50</td>
<td class='logo_field carrierwave_type' title=''></td>
<td class='name_field string_type' title='Test'>Test</td>
<td class='created_at_field datetime_type' title='January 22, 2015 23:11'>January 22, 2015 23:11</td>
<td class='updated_at_field datetime_type' title='January 22, 2015 23:11'>January 22, 2015 23:11</td>
<td class='address_1_field string_type' title='1600 Pennsylvania Ave'>1600 Pennsylvania Ave</td>
</tr>
所以我想输入&#39;测试&#39;进入我的查询并让它返回50.这是我的失败查询:
find(:xpath, "//tr[td/@title = 'Test']") do |row|
id = find(:xpath, "//td[@class = 'id_field integer_type']./@title")
return id
end
=> #<Capybara::Element tag="tr">
因此它正确返回Capybara行,但查询未找到ID。任何帮助将不胜感激。
答案 0 :(得分:0)
您的XPath表达式不正确。 .
之后不能立即]
。
id = find(:xpath, "//td[@class = 'id_field integer_type']/@title")
如果这没有帮助,请尝试两者
id = find(:xpath, "td[@class = 'id_field integer_type']/@title")
和
id = find(:xpath, ".//td[@class = 'id_field integer_type']/@title")
您甚至可能必须这样做
id = find(:xpath, "string(//td[@class = 'id_field integer_type']/@title)")
取决于XPath环境的行为。