XPath:如何在类上面找到一个类

时间:2016-12-13 09:44:02

标签: html xpath

我正在尝试访问'glyphicon-cog'类(第二个跨度)上面的类。

我有类似的东西,但它不起作用: // span [@ class ='k-link'] // span [@ class ='glyphicon glyphicon-cog cursor-pointer']

HTML代码:

<li class="k-item k-state-default k-last" role="menuitem" id="chartHeaderButtons_mn_active" style="z-index: auto;">
<span class="k-link">
    <span class="glyphicon glyphicon-cog cursor-pointer"></span>
    <span class="k-icon k-i-arrow-s"></span>
</span>

<div class="k-animation-container" style="width: 171px; height: 26px; margin-left: -2px; padding-left: 2px; padding-right: 2px; padding-bottom: 4px; overflow: hidden; display: none; position: absolute; z-index: 10002; top: 30px; left: -139px;">

    <ul class="k-group k-menu-group k-popup k-reset" role="menu" data-role="popup" style="display: none; position: absolute; font-size: 12px; font-family: Arial; font-stretch: normal; font-style: normal; font-weight: normal; line-height: normal; transform: translateY(-26px);">

        <li class="k-item k-state-default k-first k-last" role="menuitem" id="previousInstallationsOption">
            <span class="k-link">
                <input id="show-previous-installations" type="checkbox" data-bind="checked: isPreviousInstallation">
                <label for="show-previous-installations">
                    <b>Previous installations</b>
                </label>
            </span>
        </li>
    </ul>
</div>

1 个答案:

答案 0 :(得分:0)

你应该使用/..

//span[@class='k-link']//span[@class='glyphicon glyphicon-cog cursor-pointer']/..

或祖先

//span[@class='k-link']//span[@class='glyphicon glyphicon-cog cursor-pointer']//ancestor::span