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

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


Looking at this: http://selenium.googlecode.com/svn/trunk/docs/api/rb/Selenium/WebDriver/ActionBuilder.html

You can use ActionBuilder to do what you need.move_to will put the cursor in the middle of the element, you'll need to change the offsets based on that.

driver.action.move_to(element, xOffset, yOffset).   click().   perform


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 })