如何为同一页面上的两个下一个按钮创建xpath

时间:2016-04-12 16:59:17

标签: html selenium xpath selenium-webdriver automation

我的页面包含两个下一个按钮。我需要在两个按钮中单击一个特定的“下一步”按钮。这里的问题是下一个按钮都有相同的HTML内容。它们有唯一的ID,但它不是静态的。它是动态的,并且会一直在变化。 在这里如何使用任何方法识别我的元素?

以下父代码我为“下一步”按钮添加了2.这里我们只有一个名为 uId的唯一标识符:'navigationPanel' 。请你帮我一下在我的xpath创建中使用它?

<div id="idx_layout_ContentPane_102" class="dijitContentPane idxContentPane wizardNavigationPanel wizardNavigationPanelBottom" data-mojo-props="    'class' : 'wizardNavigationPanel wizardNavigationPanelBottom' , uId : 'navigationPanel' , renderHidden : true ,scParamDataFn : function() { return { 'aria-label' : this.getSimpleBundleString('Region_wizard_navigation') } } " data-mojo-type="idx/layout/ContentPane" role="region" aria-label="Wizard navigation" widgetid="idx_layout_ContentPane_102">
<span class="dijit dijitReset dijitInline dijitButton idxButtonDerived navPrevious" role="presentation" widgetid="dijit_form_Button_11">
<span class="dijit dijitReset dijitInline idxButtonDerived idxSpecialButton navNext dijitButton" role="presentation" widgetid="dijit_form_Button_12">
<span class="dijitReset dijitInline dijitButtonNode" role="presentation" data-mojo-attach-event="ondijitclick:__onClick">
<span id="dijit_form_Button_12" class="dijitReset dijitStretch dijitButtonContents" aria-labelledby="dijit_form_Button_12_label" role="button" data-mojo-attach-point="titleNode,focusNode" tabindex="0" style="-moz-user-select: none;">
<span class="dijitReset dijitInline dijitIcon idxNextPageIcon" data-mojo-attach-point="iconNode"/>
<span class="dijitReset dijitToggleButtonIconChar">●</span>
<span id="dijit_form_Button_12_label" class="dijitReset dijitInline dijitButtonText" data-mojo-attach-point="containerNode">Next</span>
</span>
</span>
<input class="dijitOffScreen" type="button" data-mojo-attach-point="valueNode" aria-hidden="true" role="presentation" tabindex="-1" data-mojo-attach-event="onclick:_onClick" value=""/>
</span>

ID总是有所不同。我需要识别“下一步”按钮1。

1 个答案:

答案 0 :(得分:0)

试试这个:

       contexto.deleteObject(p!)

        do {
            try contexto.save()
            print("Borrado ")
        } catch _ as NSError {
            print( "Error en delete")

        }

exprn末尾的[1]获取第一个匹配节点,即“下一步”按钮1。