Psl*_*Psl 1 ruby xpath cucumber capybara capybara-webkit
我需要使用capyvara从选定的单选按钮内的span标签中读取文本值
我有一个radio button后跟文本的列表及其括号内的计数.
例如:radiobutton with Thank You(82)
I what想要读取括号内选定的单选按钮数82.
我使用以下代码..但它不起作用
value=page.find(".cardFilterItemSelection[checked='checked'] + span.itemCount").text
Run Code Online (Sandbox Code Playgroud)
并尝试使用Xpath但没有得到任何东西
value=page.find(:xpath,"//input[@class = 'cardFilterItemSelection' and @checked = 'checked']/span[@class = 'itemCount']/text()")
Run Code Online (Sandbox Code Playgroud)
怎么可能?
<label id="thankyou_label" for="thankyou_radio" class="itemName radio">
<input checked="checked" tagtype="Occasion" value="Thank You" id="thankyou_radio" name="occasionGroup" class="cardFilterItemSelection" type="radio">
<span class="occasion_display_name">
Thank You
</span>
<span class="itemCount">
(82)
</span>
</label>
<label id="spring_label" class="itemName radio" for="spring_radio">
<input id="spring_radio" class="cardFilterItemSelection" type="radio" name="occasionGroup" value="Spring" tagtype="Occasion">
<span class="occasion_display_name">
Spring
</span>
<span class="itemCount">
(0)
</span>
</label>
Run Code Online (Sandbox Code Playgroud)
cry*_*o28 10
我认为你走在了正确的轨道上.但是您应该查询不是span包含的文本节点,而是查询span本身并使用XPath 轴
span = page.find(:xpath,"//input[@class = 'cardFilterItemSelection' and @checked = 'checked']/following-sibling::span[@class = 'itemCount']")
value = span.text
Run Code Online (Sandbox Code Playgroud)
但是我个人觉得css选择器更具可读性(除非你需要进行复杂的查询)
span = page.find(:css, 'input.cardFilterItemSelection[checked=checked] ~ span.itemCount')
value = span.text
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3396 次 |
| 最近记录: |