How to fill hidden field with Capybara?

后端 未结 4 743
囚心锁ツ
囚心锁ツ 2020-12-13 23:06

I\'ve already found that when I want to set value to text field, text area or password field, I can use id, name or label as something in fill_in somethin

4条回答
  •  独厮守ぢ
    2020-12-13 23:49

    You need to locate the hidden field and set its value. There are a couple ways, this is probably the simplest

    find(:xpath, "//input[@id='my_hidden_field_id']").set "my value"
    

    If you're executing a client_side script in production, you could just tell capybara to run it with a javascript-compliant driver

    page.execute_script("$('hidden_field_id').my_function()")
    

提交回复
热议问题