Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Rspec/Capybara/Selenium to interact with a canvas element

I have an HTML5 canvas element that triggers different actions depending on where it is clicked.

Is there any way I can simulate this behavior in my test specs using Capybara

like image 490
wyclin Avatar asked Jan 10 '14 18:01

wyclin


Video Answer


1 Answers

Had a look at the click code on Capybara & noticed you can pass x & y co-ordinates to where you want to click: https://github.com/teamcapybara/capybara/blob/8f86f46d2c486aa27045f853ff7696f5aa34dcf4/lib/capybara/node/element.rb#L157-L174

This is working for me on capybara:

page.find('#canvas-id').click([], { x: 50, y: 80 })
like image 155
gef Avatar answered Sep 24 '22 19:09

gef