Take the 2-minute tour ×

My configuration:


The html is as follow:

  <img id="listActorsResultsForm:actorList:1:viewActionImage" 
     src="/TM/img/icons64/kfind.gif" height="28" 
     } )" style="cursor: pointer;" title="Voir" width="28">

My image has an ajax.submit linked to the onclick event. What i'd like to do is to click on the image with capybara but all my attempts failed.

what I've tried:


I can't find the good way to click on the image so that the ajax.submit gets executed.

There's a strange behaviour

When I do:

  click_on 'listActorsResultsForm:actorList:1:viewActionImage'

the page i want to see appears, but there's an error:

Failure/Error: click_on 'listActorsResultsForm:actorList:1:viewActionImage'
   Unable to find link or button "listActorsResultsForm:actorList:1:viewActionImage"
 # ./spec/aipo_spec.rb:20:in `block (3 levels) in <top (required)>'

But in command line context (see gist for setup) it works


The link is found and the click action opens the web page

Does anyone has an idea why?

share|improve this question
What capybara driver are you using? –  Daniel Evans Jan 15 '13 at 19:05
I'm using selenium driver. config.default_driver = :selenium. and I've tried to mark the test as javascript with (:js => true) but didn't work –  jefff35 Jan 16 '13 at 8:08
My configuration: gist.github.com/4547098 –  jefff35 Jan 16 '13 at 13:22
It's like the browser is blocked, waiting for something –  jefff35 Jan 16 '13 at 13:32
add comment

1 Answer

According to the Capybara docs, "click_on" is looking specifically for a link or a button with that id, while you just have an image with that id. When you're running it from the command like, you're searching for an image with the correct id.

My Ajax isn't great, so correct me if I'm wrong, but couldn't you just wrap that image with an tag with the correct id?

share|improve this answer
I agree with you that click_on is looking for an id, the point is that when I do a clik_on('#id') after find('#id').click the page gets loaded. –  jefff35 Jan 16 '13 at 17:52
I'd really like to wrap that image with a tag or user another html tag, but it's a legacy web application and I would have to do a massive refactoring –  jefff35 Jan 16 '13 at 17:53
add comment

Your Answer


