Capybara can find but not fill_in

后端 未结 3 842
梦如初夏
梦如初夏 2021-02-13 16:50

I am having some very strange behaviour with Capybara. It stubbornly refuses to fill in the fields of my login form.

3条回答
  •  梦谈多话
    2021-02-13 17:46

    The locator for find and fill_in are different:

    • find - When the first parameter is not a symbol, it is assumed to be the Capybara.default_selector - ie a css-selector or xpath.
    • fill_in - The first parameter is the field's name, id or label text.

    The string "#user_email" represents a css-selector. This is why it works in find but not fill_in.

    For fill_in to work, you need to just pass in the id value - ie just "user_email".

    within("#login_form"){ fill_in("user_email", with: "foo@example.com")}  
    

提交回复
热议问题