【问题标题】:How to create xpath for two next button available on the same page如何为同一页面上的两个下一个按钮创建 xpath
【发布时间】:2016-08-03 10:35:46
【问题描述】:

我的页面包含两个下一步按钮。在这里我需要单击两个中的一个特定的“下一步”按钮。这里的问题是两个下一个按钮都具有相同的 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。

【问题讨论】:

  • 在这种情况下,您需要借助这些按钮的父级。你能粘贴按钮前后的html吗?
  • @pArAs 更新了父代码。我们有一个名为 uId 的唯一标识符。请您帮我看看如何在 xpath 中使用它。

标签: html selenium xpath selenium-webdriver automation


【解决方案1】:

试试这个:

//*[contains(@class,'flagButtonText') and contains(@id,'flag_form_Button')][1]

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

【讨论】:

  • 我试过关注,但它正在识别所有按钮。不是第一个。 //*[contains(@class,'book flagInline flagButtonText') and contains(@data-mojo-attach-point, 'containerNode')][1]
  • 把你的网页链接发给我。如果你不想发布 - 然后发送到我的 gmail:: sree.cs10@gmail.com
  • 如果没有 VPN,您将无法访问该链接。因此,如果您需要更多详细信息,请告诉我。我已经为特定博客粘贴了整个 HTML 代码。因为我有一个名为 uId 的唯一 ID,通过使用那我如何创建我的 xpath。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-08-09
  • 1970-01-01
  • 2012-03-21
  • 2017-01-27
  • 1970-01-01
  • 2014-07-22
相关资源
最近更新 更多