How to fill hidden field with Capybara?

后端 未结 4 740
囚心锁ツ
囚心锁ツ 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:41

    This is what worked for me

    find_field(id: 'your_hidden_field_id', type: :hidden).set('Field value here')
    
      
    
    0 讨论(0)
  • 2020-12-13 23:42

    There are many ways to achieve the same result. The one I like the most is:

    first('input#id.class', visible: false).set("your value")
    
    0 讨论(0)
  • 2020-12-13 23:44

    If you're using poltergeist/phantomjs as a driver and jquery isn't working for ya, there's always good old fashioned js:

    page.execute_script("document.getElementById('#some-id').value = 'some-value'");
    
    0 讨论(0)
  • 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()")
    
    0 讨论(0)
提交回复
热议问题