I’m using Rspec and Capybara.
How can I write a step to click on an image? I have been unable to find a good way to get Capybara to see the image as a link.
Thanks
Example of 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">
Any suggestions?
It shouldn’t be any different to clicking a normal link. I don’t see how you would go about selecting an individual link in your example though, without any uniquely identifiable attributes on the link.
If you can’t change the markup, you may need to use XPath to actually select the
hrefelement by the URL e.g.Would give you the first link, and then
Should click it as normal.
EDIT: Just to clarify, the important thing is that you select the
aelement and click it, not theimg.