bevanb
bevanb

Reputation: 8511

Rspec+capybara request specs: testing form submit with invisible button: best way to make button invisible?

I have a one-textfield form on my app. I don't want a visible submit button (users have to hit 'enter' to submit). I understand you still want the button there for accessibility, so I move it offscreen.

I'm testing with Capybara. When I click_on my-button, it gives me this error:

Failure/Error: click_on "gimme-your-cc"
 Selenium::WebDriver::Error::MoveTargetOutOfBoundsError:
   Element cannot be scrolled into view:[object HTMLInputElement]

That particular spec is done within a js: true block so it uses webdriver and firefox.

Is there a good way to test submitting that button? Making it the button display:hidden didn't work either and I think that solution isn't very accessible anyway.

Upvotes: 0

Views: 1271

Answers (1)

apneadiving
apneadiving

Reputation: 115511

A good work around would be to use javascript:

page.execute_script("$('#submit_id').click();")

Upvotes: 2

Related Questions