我用的是rspec和水豚。
如何编写单击图像的步骤?我一直找不到一个好办法让水豚把这张图片看作是一个链接。
谢谢
HTML示例

<a title="inGroups" href="/de/users/index/roles-list/serviceID/1112/inGroup/1">
  <img border="0" alt="inGroups" src="/themes/system/images/icon/16/role_activate.png">

<a title="inGroups" href="/de/users/index/roles-list/serviceID/1114/inGroup/1">
   <img border="0" alt="inGroups" src="/themes/system/images/icon/16/role_activate.png">

<a title="notInGroups" href="/de/users/index/roles-list/serviceID/1112/inGroup/0">
   <img border="0" alt="notInGroups" src="/themes/system/images/icon/16/role_deactivate.png">

<a title="notInGroups" href="/de/users/index/roles-list/serviceID/1114/inGroup/0">
    <img border="0" alt="notInGroups" src="/themes/system/images/icon/16/role_deactivate.png">

有什么建议吗?

最佳答案

点击一个普通的链接应该没什么不同。不过,我不知道在示例中如何选择单个链接,因为链接上没有任何唯一可识别的属性。
如果无法更改标记,则可能需要使用xpath通过url实际选择href元素,例如。

my_link = find(:xpath, "//a[contains(@href,'1114/inGroup/1')]")

会给你第一个链接,然后
my_link.click

应该正常点击。
编辑:为了澄清,重要的是选择a元素并单击它,而不是img

10-07 19:17
查看更多