为什么Capybara坚持认为我隐藏的领域是可见的?

时间:2016-03-03 21:54:34

标签: html ruby-on-rails capybara

我有一个名为user_email的隐藏字段。它看起来像这样:

<input type="hidden" value="foo@bar.com" name="user[email]" id="user_email">

出于某种原因,Capybara确信这是一个可见元素:

$ page.find '#user_email'
#<Capybara::Node::Element tag="input" path="/html/body/div[2]/div/section/div/form/div[1]/div[4]/input">

$ page.find '#user_email', visible: :visible
#<Capybara::Node::Element tag="input" path="/html/body/div[2]/div/section/div/form/div[1]/div[4]/input">

$ page.has_css? '#user_email', visible: :visible     # => true  
$ page.has_css? '#user_email', visible: false        # => true    
$ page.has_css? '#user_email', visible: true         # => true  
$ page.has_css? '#user_email', visible: :hidden      # => false   
$ page.all('#user_email').count                      # => 1
$ page.all('input[type=hidden]#user_email').count    # => 1

设置Capybara.ignore_hidden_elements无效。我重新启动机器,以确保我不会发疯。我在这里遗漏了什么,或者不应该隐藏一个隐藏的领域?

1 个答案:

答案 0 :(得分:0)

You haven't responded to what driver you're using, but it looks like the default rack_test driver has a bug where it incorrectly considers hidden type inputs to be visible. A fix has been added in the master branch of Capybara. The selenium driver correctly considers it invisible -- not sure about the other drivers available (capybara-webkit, poltergeist, etc)