Brandon
Brandon

Reputation: 3130

Capybara + Selenium / Webkit : Selecting *within* a div (rails / rspec)

Good evening,

I'm trying to set up a request spec with RSpec / Capybara for a page that contains a Flot graph. I have the page set up such that the user has to click on a marked element within the graph (tick/data point) to continue. Obviously the graph is generated with Javascript (flot).

Is there a way to get capybara/selenium to click on a specific x/y position with the chart div? I can measure it out in the development environment such that it should hit the datapoint in the test.

I have found ways to generate this click event with javascript:

$(document.elementFromPoint(x, y)).click();

But I don't think there is a way to get this to work in RSpec. I'm looking for something more like:

find(".overlay").click(top:10px; left:50px;) # click offset from the top and left of graph div
response.body.should have_selector(# stuff that should show up on the page)

Not sure if it makes any difference, but I prefer Selenium over webkit at the moment so that I can see what it is doing... will switch to webkit once tests are running.

Upvotes: 1

Views: 938

Answers (1)

zetetic
zetetic

Reputation: 47548

Capybara should allow you to execute Javascript from within an example when the driver supports it, e.g.:

page.execute_script('$(document.elementFromPoint(10, 50)).click();')

Upvotes: 1

Related Questions