{"action":"created","issue":{"url":"https://api.github.com/repos/jnicklas/capybara/issues/1378","labels_url":"https://api.github.com/repos/jnicklas/capybara/issues/1378/labels{/name}","comments_url":"https://api.github.com/repos/jnicklas/capybara/issues/1378/comments","events_url":"https://api.github.com/repos/jnicklas/capybara/issues/1378/events","html_url":"https://github.com/jnicklas/capybara/issues/1378","id":40137115,"number":1378,"title":"Field suggestions for \"fill_in\"","user":{"login":"Paxa","id":26019,"avatar_url":"https://avatars.githubusercontent.com/u/26019?v=3","gravatar_id":"","url":"https://api.github.com/users/Paxa","html_url":"https://github.com/Paxa","followers_url":"https://api.github.com/users/Paxa/followers","following_url":"https://api.github.com/users/Paxa/following{/other_user}","gists_url":"https://api.github.com/users/Paxa/gists{/gist_id}","starred_url":"https://api.github.com/users/Paxa/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Paxa/subscriptions","organizations_url":"https://api.github.com/users/Paxa/orgs","repos_url":"https://api.github.com/users/Paxa/repos","events_url":"https://api.github.com/users/Paxa/events{/privacy}","received_events_url":"https://api.github.com/users/Paxa/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":10,"created_at":"2014-08-13T09:26:46Z","updated_at":"2015-04-23T16:53:08Z","closed_at":null,"body":"This changes save me alot of time. Because when I make mistake in field name is annoying.\r\n\r\n```ruby\r\nmodule Capybara::Node::Actions\r\n  def fill_in(locator, options = {})\r\n    raise \"Must pass a hash containing 'with'\" if not options.is_a?(Hash) or not options.has_key?(:with)\r\n    with = options.delete(:with)\r\n    find(:fillable_field, locator, options).set(with)\r\n  rescue Capybara::ElementNotFound => exception\r\n    all_fields = [];\r\n    all(:fillable_field).each do |el|\r\n      all_fields << el[:id] || el[:name]\r\n      if el[:id].present?\r\n        label_selector = %{label[for=#{el[:id]}]}\r\n        if has_css?(label_selector)\r\n          label = find(label_selector)\r\n          all_fields << label.text\r\n        end\r\n      end\r\n    end\r\n    raise Capybara::ElementNotFound.new(%{Unable to find field \"#{locator}\", did you mean one if this: #{all_fields}})\r\n  end\r\nend\r\n```\r\n\r\n```\r\nUnable to find field \"Transaction fee1\", did you mean one if this: [\"Transaction fee\", ...]\r\n```\r\n\r\nI think it would be nice to have it in capybara, what do you think?"},"comment":{"url":"https://api.github.com/repos/jnicklas/capybara/issues/comments/95651854","html_url":"https://github.com/jnicklas/capybara/issues/1378#issuecomment-95651854","issue_url":"https://api.github.com/repos/jnicklas/capybara/issues/1378","id":95651854,"user":{"login":"twalpole","id":16556,"avatar_url":"https://avatars.githubusercontent.com/u/16556?v=3","gravatar_id":"","url":"https://api.github.com/users/twalpole","html_url":"https://github.com/twalpole","followers_url":"https://api.github.com/users/twalpole/followers","following_url":"https://api.github.com/users/twalpole/following{/other_user}","gists_url":"https://api.github.com/users/twalpole/gists{/gist_id}","starred_url":"https://api.github.com/users/twalpole/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/twalpole/subscriptions","organizations_url":"https://api.github.com/users/twalpole/orgs","repos_url":"https://api.github.com/users/twalpole/repos","events_url":"https://api.github.com/users/twalpole/events{/privacy}","received_events_url":"https://api.github.com/users/twalpole/received_events","type":"User","site_admin":false},"created_at":"2015-04-23T16:53:08Z","updated_at":"2015-04-23T16:53:08Z","body":"@pavel - The \"if we make it for find it will give wrong suggestions\" is exactly my point about not being able to do it for all ElementNotFound errors.  Doing it for all the methods in actions.rb is probably possible.\r\n\r\nThe issues I have with your other two suggestions are \r\n1. Your #fill_in method is incomplete in the suggestions it offers (as detailed in a previous message)\r\n2. Both of these methods have a race condition where it's possible to get an error like\r\n   Unable to find field \"Title\" did you mean one of these [\"Title\", ....]  \r\n   Where it's telling you it couldn't find a field and then asking if you meant that exact same field.  This is because of the time delay between the field not being found and then getting all the available things on the page.   I don't think there's really a clean way to fix that possibility so it should probably be checked for when the error message is generated and make a statement about the race condition if it happens.  This may have to take into the match mode currently being used.\r\n3.  This behavior would need to be turned on/off with a setting  -  Capybara.suggest_on_action_failure  or something like that\r\n"}}