网页中有三个具有动态ID的保存按钮。指导我如何定义最佳xpath,目前我已经应用了完整的xpath起始html节点。
首先保存按钮HTML代码
<button id="j_idt131" name="j_idt131" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only button" onclick="PrimeFaces.ab({source:'j_idt131',update:'csqa_form',oncomplete:function(xhr,status,args){if (args && !args.validationFailed) qaChangeDialog.show();}});return false;" type="submit" role="button" aria-disabled="false"><span class="ui-button-text ui-c">Save</span></button>
第二个保存按钮HTML代码
<button id="j_idt104" name="j_idt104" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only button" onclick="PrimeFaces.ab({source:'j_idt104',update:'cemail_form',oncomplete:function(xhr,status,args){if (args && !args.validationFailed) emailChangeDialog.show();}});return false;" type="submit" role="button" aria-disabled="false"><span class="ui-button-text ui-c">Save</span></button>
第三个保存按钮HTML代码
<button id="j_idt82" name="j_idt82" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only button" onclick="PrimeFaces.ab({source:'j_idt82',update:'cpwd_form',oncomplete:function(xhr,status,args){if (args && !args.validationFailed) pwdChangeDialog.show();}});return false;" type="submit" role="button" aria-disabled="false"><span class="ui-button-text ui-c">Save</span></button>
答案 0 :(得分:1)
由于你知道按钮的顺序,你可以试试这个xpath,
//button[contains(@id,"j_idt")][1]
//button[contains(@id,"j_idt")][2]
//button[contains(@id,"j_idt")][3]
答案 1 :(得分:0)