如何为动态元素创建xpath?

时间:2016-04-11 16:56:39

标签: selenium xpath automation

如何为跟随动态元素创建xpath。

注意 - 这里我不能使用id组件。因为它每次都有所不同。在这个类中很多其他2个按钮都有“添加”名称。所以id组件将动态改变,同样的类也用于其他按钮。

    <span class="bookReset bookInline bookButtonNode" role="presentation" data-dojo-attach-event="onbookclick:__onClick">
<span id="book_form_Button_108" class="bookReset bookStretch bookButtonContents" aria-labelledby="book_form_Button_108_label" role="button" data-dojo-attach-point="titleNode,focusNode" tabindex="0" style="-moz-user-select: none;">
<span class="bookReset bookInline bookIcon icon-add" data-dojo-attach-point="iconNode"/>
<span class="bookReset bookToggleButtonIconChar">.</span>
<span id="book_form_Button_108_label" class="bookReset bookInline bookButtonText" data-dojo-attach-point="containerNode">Add</span>
</span>
</span>

2 个答案:

答案 0 :(得分:0)

试试这个

//span[@class="dual dualInline dijitButtonText"][contains(text(), "Add")]

答案 1 :(得分:0)

试试这个:

//*[@data-dojo-attach-point='containerNode' and text()='Add']