fill_in hidden_​​field with capybara error

时间:2014-12-14 05:18:35

标签: ruby-on-rails rspec selenium-webdriver capybara

我正在尝试设置hidden_​​field的值但是我收到错误:

in pry

find("#element_id", visible: false)
=> #<Capybara::Element tag="input">

现在尝试设置它会返回错误

find("#element_id", visible: false).set true
Selenium::WebDriver::Error::ElementNotVisibleError: element not visible
(Session info: chrome=39.0.2171.95)
(Driver info: chromedriver=2.12.301326     (093c7e07b4a916b690e784b0374c7f618f1ea4be),platform=Mac OS X 10.10.1 x86_64)
from /Users/admin/.rvm/gems/ruby-2.1.3/gems/selenium-webdriver-2.44.0/lib/selenium/webdriver/remote/response.rb:52:in `assert_ok'

任何想法都会很棒!我也尝试过使用xpath,但无济于事。任何想法都会很棒。

1 个答案:

答案 0 :(得分:1)

使用这个工作..

page.execute_script(“$(‘#hidden_input_id’).val(‘value’)”)

在这里找到答案:

https://devmaheshwari.wordpress.com/2013/09/20/capybara-cheat-sheet/