Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to target localized button with RSpec and Capybara?

I am using RSpec and Capybara for Ruby on Rails testing.

My Rails app is localized for a number of different languages (English, German, etc.).

For example, I would like Capybara to submit a form but obviously can't use its value to select it because the value changes depending on the language that has been chosen.

This won't work in my case:

click_button("Create my account")

Is there any way to simply select the first input[type="submit"] element on the page with Capybara?

Thanks for any help.

like image 323
Tintin81 Avatar asked Nov 30 '22 04:11

Tintin81


2 Answers

You can assign an id to the button and click it

click_button("button_id")

Source: http://rubydoc.info/github/jnicklas/capybara/master/Capybara/Node/Actions#click_button-instance_method

like image 55
Billy Chan Avatar answered Dec 02 '22 17:12

Billy Chan


I'd say:

find('input[type="submit"]').first.click

but give it a class or an id, it's much safer.

like image 35
apneadiving Avatar answered Dec 02 '22 17:12

apneadiving