Need to click at a point on a map with Capybara? Now you can do it

Dzmitry Kavalionak
Sep 1, 2018 · 1 min read

Testing my Rails projects I quite often needed to click on a point on a map. To select a location or checkin for example

Capybara 3 allows to do this with ease:

find('#map').click(x, y)

But Capybara 2 doesn’t have this functionality. Before upgrade to Capybara 3 I used handwritten click_at capybara helper

I decided to extract the helper code into a small library for the sake of consistency. It exposes click_at helper and uses Capybara 3 api under the hood if installed capybara version is greater than 3.0.0. Otherwise it fires 'click' Javascript event to achieve the result:

click_at(x, y)                # click the page at (x, y)
click_at(x, y, css: '#map') # click map at (x, y)

You can see more examples in the README. You can download the code from Rubygems

Happy testing!

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade