如何使用Capybara,Selenium和Cucumber框架处理灯箱?

时间:2012-04-03 05:08:21

标签: selenium cucumber capybara

我正在尝试运行一个可以处理jQuery灯箱的测试套件。 Lightbox包含textarea和提交按钮。在灯箱出现之前,这两个字段都是隐藏的。

但是Selenium并不了解这些元素在灯箱中的可见性。它只显示以下错误。

And I fill comment box with "Text !!" # features/step_definitions/web_steps.rb:333
  Element is not currently visible and so may not be interacted with (Selenium::WebDriver::Error::ElementNotVisibleError)
  [remote server] file:///tmp/webdriver-profile20120403-6182-1rd9z23/extensions/fxdriver@googlecode.com/components/command_processor.js:9509:in `unknown'
  [remote server] file:///tmp/webdriver-profile20120403-6182-1rd9z23/extensions/fxdriver@googlecode.com/components/command_processor.js:10510:in `unknown'
  [remote server] file:///tmp/webdriver-profile20120403-6182-1rd9z23/extensions/fxdriver@googlecode.com/components/command_processor.js:10529:in `unknown'
  [remote server] file:///tmp/webdriver-profile20120403-6182-1rd9z23/extensions/fxdriver@googlecode.com/components/command_processor.js:10534:in `unknown'
  [remote server] file:///tmp/webdriver-profile20120403-6182-1rd9z23/extensions/fxdriver@googlecode.com/components/command_processor.js:10482:in `unknown'
  (eval):2:in `send'
  (eval):2:in `fill_in'
  ./features/step_definitions/web_steps.rb:335:in `/^I fill comment box with "([^"]*)"$/'
  features/courses_flow.feature:21:in `And I fill comment box with "Text !!"'

1 个答案:

答案 0 :(得分:1)

作为临时解决方法,您可以让水豚看到隐藏的元素。我建议谨慎使用它并添加一个特殊标记,并仅在某些情况下启用它:

Before('@ignore-hidden-elements') do
  Capybara.ignore_hidden_elements = true
end