XPATH,返回特定div中的特定元素

时间:2018-06-06 06:11:22

标签: xpath

从下面这个特殊的div中,我试图获取可用的大小,这是"值"这里的财产:

<input id="swatch-0-s-6072559239" type="radio" name="option-0" value="S" class="">

所以我需要回复:XS,S,M,L,XL

我一直在尝试各种变体:

//div[@class='swatch_options']following-sibling::input@value

但这不起作用。

<div class="swatch clearfix" data-option-index="0"> <div class="option_title">Size</div> <input id="swatch-0-xs-6072559239" type="radio" name="option-0" value="XS" checked="" class=""> <div data-value="XS" class="swatch-element xs-swatch"> <label for="swatch-0-xs-6072559239">
            XS <span class="crossed-out"></span></label></div> <input id="swatch-0-s-6072559239" type="radio" name="option-0" value="S" class=""> <div data-value="S" class="swatch-element s-swatch available"> <label for="swatch-0-s-6072559239">
            S <span class="crossed-out"></span></label></div> <input id="swatch-0-m-6072559239" type="radio" name="option-0" value="M" class=""> <div data-value="M" class="swatch-element m-swatch available"> <label for="swatch-0-m-6072559239">
            M <span class="crossed-out"></span></label></div> <input id="swatch-0-l-6072559239" type="radio" name="option-0" value="L" class=""> <div data-value="L" class="swatch-element l-swatch available"> <label for="swatch-0-l-6072559239">
            L <span class="crossed-out"></span></label></div> <input id="swatch-0-xl-6072559239" type="radio" name="option-0" value="XL" class=""> <div data-value="XL" class="swatch-element xl-swatch available"> <label for="swatch-0-xl-6072559239">
            XL <span class="crossed-out"></span></label></div>

1 个答案:

答案 0 :(得分:0)

以下兄弟和输入@值的xpath语法错误,

尝试以下

//div[@class='swatch clearfix']/input[@name='option-0']

此外,您的父div标签未关闭。

检查输出

https://codepen.io/ajanth2012/pen/MXaPpp?editors=1010