【问题标题】:How to get the last element in Selenium IDE thats always changing如何获取 Selenium IDE 中总是在变化的最后一个元素
【发布时间】:2012-08-15 14:01:47
【问题描述】:

在代码中:

<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()],但它给了我一个错误

【问题讨论】:

    标签: xpath selenium


    【解决方案1】:

    我想你想为 onclick 属性的值做一个开始:

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

    【讨论】:

    • 谢谢!这对我帮助很大。我尝试在 Google 上找了几个小时,但没有找到答案。
    • xpath document 很难阅读,但我发现它至少列出了所有方法。然后知道你想要的方法,它可以更容易地谷歌搜索示例。
    猜你喜欢
    • 1970-01-01
    • 2021-10-26
    • 1970-01-01
    • 1970-01-01
    • 2020-04-06
    • 2013-04-19
    • 1970-01-01
    • 2018-07-27
    • 1970-01-01
    相关资源
    最近更新 更多