如何在Selenium IDE中获取总是在变化的最后一个元素

时间:2012-08-14 18:25:46

标签: xpath selenium

在代码中:

<img style="cursor: pointer; background-color: transparent;" onclick="changeTeamHint(2155);" src="/images/icon_edit_inactive.png">

onclick="changeTeamHint(2155);"总是在变化。当我向表单添加更多字段时,数字会增加。

如何获取Selenium IDE中的最后一个元素?例如,如果我使用"changeTeamHint(2156)"添加文本字段,如何使用Selenium IDE选择最新的文本字段?如果是2157,则选择2157.等等。

这是我到目前为止所得到的:xpath=(//img[@style='cursor:pointer;'])[last()]

但我的同事告诉我试图通过onclick找到它,这就是我的工作:xpath=(//img[@onclick='changeTeamHint(2155);'])[last()]

我试过了xpath=(//img[@onclick='changeTeamHint();'])[last()],但它给了我一个错误

1 个答案:

答案 0 :(得分:6)

我认为你想对onclick属性的值进行一次启动:

xpath=(//img[starts-with(@onclick, 'changeTeamHint')])[last()]
相关问题