xpath用于在Robot FrameWork中找到id为动态的按钮

时间:2014-12-29 10:49:24

标签: xpath robotframework

我正在使用RobotFramework进行自动化测试,我在点击一个id为动态的按钮时面临一个问题,它是一个' +'点击的符号我会得到一个弹出窗口。



<div id="button-1571" class="x-btn x-box-item x-toolbar-item x-btn-default-toolbar-small x-icon x-btn-icon x-btn-default-toolbar-small-icon" style="border-width: 1px; left: 373px; margin: 0px; top: 6px;">

    <em id="button-1571-btnWrap">
        <button id="button-1571-btnEl" class="x-btn-center" autocomplete="off" role="button" hidefocus="true" type="button" style="height: 16px;">
            <span id="button-1571-btnInnerEl" class="x-btn-inner" style="margin: -1px 0px;"></span>
            <span id="button-1571-btnIconEl" class="x-btn-icon icon-plus"></span>
        </button>
    </em>

</div>
&#13;
&#13;
&#13;

以下是我用来点击按钮的代码

点击按钮xpath=//div[@id='button-1571']/descendant::button[contains(@class, 'x-btn-center')]/span[contains(@class,'x-btn-icon icon-plus')]

但它不能正常工作请建议如何解决这个问题

1 个答案:

答案 0 :(得分:0)

我只能测试XPath,但是用

//div[@id='button-1571']/descendant::button[contains(@class, 'x-btn-center')]/  
                         span[contains(@class,'x-btn-icon icon-plus')]

它不是被选中的button,而是span

<span id="button-1571-btnIconEl" class="x-btn-icon icon-plus" />

将XPath更改为

//div[@id='button-1571']/descendant::button[contains(@class, 'x-btn-center')]/  
                         span[contains(@class,'x-btn-icon icon-plus')]/..

或者,正如第二种符号

//div[@id='button-1571']/descendant::button[contains(@class, 'x-btn-center')]/
                     span[contains(@class,'x-btn-icon icon-plus')]/parent::button

它是button的父span,是上述XPath的结果:

<button id="button-1571-btnEl" class="x-btn-center" autocomplete="off" 
        role="button" hidefocus="true" type="button" style="height: 16px;">
  <span id="button-1571-btnInnerEl" class="x-btn-inner" style="margin: -1px 0px;" />
  <span id="button-1571-btnIconEl" class="x-btn-icon icon-plus" />
</button>