How to have a field that has a different params value to the displayed name
up vote
0
down vote
favorite
I have a form that collects an email address.
<%= form_tag accounts_path, :method => :post do %>
<div class="field">
<%= label_tag :email %><br />
<%= text_field_tag :homeEmail %>
</div>
<div class="Section-button">
<div class="actions">
<%= submit_tag "Update", class: 'btn btn-primary' %>
</div>
</div>
<% end %>
I have the field tag for the email being :homeEmail because I want to recover it in the controller using params[:homeEmail].
I want to use a capybara feature spec test such as
fill_in 'Email', with: user.email, match: :first
click_button Update
but I receive the error:
Unable to find visible field "Email" that is not disabled within #<Capybara::Node::Element
The element is not disabled, and when I try the page in development mode it works. The test fills in the field if I just change the text_field_tag to
<%= text_field_tag :email %>
but this does not work in the controller because the params is params[:email] not params[:homeEmail].
How do I get this test working?
ruby-on-rails rspec capybara
add a comment |
up vote
0
down vote
favorite
I have a form that collects an email address.
<%= form_tag accounts_path, :method => :post do %>
<div class="field">
<%= label_tag :email %><br />
<%= text_field_tag :homeEmail %>
</div>
<div class="Section-button">
<div class="actions">
<%= submit_tag "Update", class: 'btn btn-primary' %>
</div>
</div>
<% end %>
I have the field tag for the email being :homeEmail because I want to recover it in the controller using params[:homeEmail].
I want to use a capybara feature spec test such as
fill_in 'Email', with: user.email, match: :first
click_button Update
but I receive the error:
Unable to find visible field "Email" that is not disabled within #<Capybara::Node::Element
The element is not disabled, and when I try the page in development mode it works. The test fills in the field if I just change the text_field_tag to
<%= text_field_tag :email %>
but this does not work in the controller because the params is params[:email] not params[:homeEmail].
How do I get this test working?
ruby-on-rails rspec capybara
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have a form that collects an email address.
<%= form_tag accounts_path, :method => :post do %>
<div class="field">
<%= label_tag :email %><br />
<%= text_field_tag :homeEmail %>
</div>
<div class="Section-button">
<div class="actions">
<%= submit_tag "Update", class: 'btn btn-primary' %>
</div>
</div>
<% end %>
I have the field tag for the email being :homeEmail because I want to recover it in the controller using params[:homeEmail].
I want to use a capybara feature spec test such as
fill_in 'Email', with: user.email, match: :first
click_button Update
but I receive the error:
Unable to find visible field "Email" that is not disabled within #<Capybara::Node::Element
The element is not disabled, and when I try the page in development mode it works. The test fills in the field if I just change the text_field_tag to
<%= text_field_tag :email %>
but this does not work in the controller because the params is params[:email] not params[:homeEmail].
How do I get this test working?
ruby-on-rails rspec capybara
I have a form that collects an email address.
<%= form_tag accounts_path, :method => :post do %>
<div class="field">
<%= label_tag :email %><br />
<%= text_field_tag :homeEmail %>
</div>
<div class="Section-button">
<div class="actions">
<%= submit_tag "Update", class: 'btn btn-primary' %>
</div>
</div>
<% end %>
I have the field tag for the email being :homeEmail because I want to recover it in the controller using params[:homeEmail].
I want to use a capybara feature spec test such as
fill_in 'Email', with: user.email, match: :first
click_button Update
but I receive the error:
Unable to find visible field "Email" that is not disabled within #<Capybara::Node::Element
The element is not disabled, and when I try the page in development mode it works. The test fills in the field if I just change the text_field_tag to
<%= text_field_tag :email %>
but this does not work in the controller because the params is params[:email] not params[:homeEmail].
How do I get this test working?
ruby-on-rails rspec capybara
ruby-on-rails rspec capybara
asked Nov 19 at 8:18
Obromios
4,01322764
4,01322764
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
up vote
1
down vote
accepted
fill_in
finds the element to fill by name
, id
, or associated label text. When you're doing fill_in 'Email', ...
I assume you're intending it to use the associated label text option. The issue you're having is that the label isn't actually associated with the field (if you look at the HTML source you'll see the labels for
attribute doesn't match the inputs id
attribute). The fix is to change your view to correctly associate the label with the field
<%= form_tag accounts_path, :method => :post do %>
<div class="field">
<%= label_tag :homeEmail, 'Email' %><br />
<%= text_field_tag :homeEmail %>
</div>
...
Then your fill_in 'Email', with: user.email
should work correctly
add a comment |
up vote
1
down vote
Instead of doing:
fill_in 'Email', with: user.email, match: :first
You should do:
fill_in 'homeEmail', with: user.email, match: :first
Since capybara tries to find an element with id or name attributes if you're doing <%= text_field_tag :homeEmail %>
it will generate <input type="text" name="homeEmail" id="homeEmail">
but while filling it you're using Email
as a selector for which capybara is not able to find any element.
Let me know if it helps!
I have upvoted this because it works and is potentially useful in other cases, but I have accepted Walpole's answer because it allows me to use the test without modification.
– Obromios
Nov 21 at 3:21
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
fill_in
finds the element to fill by name
, id
, or associated label text. When you're doing fill_in 'Email', ...
I assume you're intending it to use the associated label text option. The issue you're having is that the label isn't actually associated with the field (if you look at the HTML source you'll see the labels for
attribute doesn't match the inputs id
attribute). The fix is to change your view to correctly associate the label with the field
<%= form_tag accounts_path, :method => :post do %>
<div class="field">
<%= label_tag :homeEmail, 'Email' %><br />
<%= text_field_tag :homeEmail %>
</div>
...
Then your fill_in 'Email', with: user.email
should work correctly
add a comment |
up vote
1
down vote
accepted
fill_in
finds the element to fill by name
, id
, or associated label text. When you're doing fill_in 'Email', ...
I assume you're intending it to use the associated label text option. The issue you're having is that the label isn't actually associated with the field (if you look at the HTML source you'll see the labels for
attribute doesn't match the inputs id
attribute). The fix is to change your view to correctly associate the label with the field
<%= form_tag accounts_path, :method => :post do %>
<div class="field">
<%= label_tag :homeEmail, 'Email' %><br />
<%= text_field_tag :homeEmail %>
</div>
...
Then your fill_in 'Email', with: user.email
should work correctly
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
fill_in
finds the element to fill by name
, id
, or associated label text. When you're doing fill_in 'Email', ...
I assume you're intending it to use the associated label text option. The issue you're having is that the label isn't actually associated with the field (if you look at the HTML source you'll see the labels for
attribute doesn't match the inputs id
attribute). The fix is to change your view to correctly associate the label with the field
<%= form_tag accounts_path, :method => :post do %>
<div class="field">
<%= label_tag :homeEmail, 'Email' %><br />
<%= text_field_tag :homeEmail %>
</div>
...
Then your fill_in 'Email', with: user.email
should work correctly
fill_in
finds the element to fill by name
, id
, or associated label text. When you're doing fill_in 'Email', ...
I assume you're intending it to use the associated label text option. The issue you're having is that the label isn't actually associated with the field (if you look at the HTML source you'll see the labels for
attribute doesn't match the inputs id
attribute). The fix is to change your view to correctly associate the label with the field
<%= form_tag accounts_path, :method => :post do %>
<div class="field">
<%= label_tag :homeEmail, 'Email' %><br />
<%= text_field_tag :homeEmail %>
</div>
...
Then your fill_in 'Email', with: user.email
should work correctly
answered Nov 19 at 11:15
Thomas Walpole
29.3k32546
29.3k32546
add a comment |
add a comment |
up vote
1
down vote
Instead of doing:
fill_in 'Email', with: user.email, match: :first
You should do:
fill_in 'homeEmail', with: user.email, match: :first
Since capybara tries to find an element with id or name attributes if you're doing <%= text_field_tag :homeEmail %>
it will generate <input type="text" name="homeEmail" id="homeEmail">
but while filling it you're using Email
as a selector for which capybara is not able to find any element.
Let me know if it helps!
I have upvoted this because it works and is potentially useful in other cases, but I have accepted Walpole's answer because it allows me to use the test without modification.
– Obromios
Nov 21 at 3:21
add a comment |
up vote
1
down vote
Instead of doing:
fill_in 'Email', with: user.email, match: :first
You should do:
fill_in 'homeEmail', with: user.email, match: :first
Since capybara tries to find an element with id or name attributes if you're doing <%= text_field_tag :homeEmail %>
it will generate <input type="text" name="homeEmail" id="homeEmail">
but while filling it you're using Email
as a selector for which capybara is not able to find any element.
Let me know if it helps!
I have upvoted this because it works and is potentially useful in other cases, but I have accepted Walpole's answer because it allows me to use the test without modification.
– Obromios
Nov 21 at 3:21
add a comment |
up vote
1
down vote
up vote
1
down vote
Instead of doing:
fill_in 'Email', with: user.email, match: :first
You should do:
fill_in 'homeEmail', with: user.email, match: :first
Since capybara tries to find an element with id or name attributes if you're doing <%= text_field_tag :homeEmail %>
it will generate <input type="text" name="homeEmail" id="homeEmail">
but while filling it you're using Email
as a selector for which capybara is not able to find any element.
Let me know if it helps!
Instead of doing:
fill_in 'Email', with: user.email, match: :first
You should do:
fill_in 'homeEmail', with: user.email, match: :first
Since capybara tries to find an element with id or name attributes if you're doing <%= text_field_tag :homeEmail %>
it will generate <input type="text" name="homeEmail" id="homeEmail">
but while filling it you're using Email
as a selector for which capybara is not able to find any element.
Let me know if it helps!
answered Nov 19 at 9:43
eurodo061
364
364
I have upvoted this because it works and is potentially useful in other cases, but I have accepted Walpole's answer because it allows me to use the test without modification.
– Obromios
Nov 21 at 3:21
add a comment |
I have upvoted this because it works and is potentially useful in other cases, but I have accepted Walpole's answer because it allows me to use the test without modification.
– Obromios
Nov 21 at 3:21
I have upvoted this because it works and is potentially useful in other cases, but I have accepted Walpole's answer because it allows me to use the test without modification.
– Obromios
Nov 21 at 3:21
I have upvoted this because it works and is potentially useful in other cases, but I have accepted Walpole's answer because it allows me to use the test without modification.
– Obromios
Nov 21 at 3:21
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53370692%2fhow-to-have-a-field-that-has-a-different-params-value-to-the-displayed-name%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown