2012-04-03 141 views
0

我試圖運行一個測試套件來處理jQuery的燈箱。燈箱包含一個textarea和一個提交按鈕。在燈箱出現之前,這兩個字段都是隱藏的。如何處理水豚,硒和黃瓜框架的燈箱?

但是硒並不瞭解這些元素在燈箱中的可見性。它只是顯示以下錯誤。

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/[email protected]/components/command_processor.js:9509:in `unknown' 
    [remote server] file:///tmp/webdriver-profile20120403-6182-1rd9z23/extensions/[email protected]/components/command_processor.js:10510:in `unknown' 
    [remote server] file:///tmp/webdriver-profile20120403-6182-1rd9z23/extensions/[email protected]/components/command_processor.js:10529:in `unknown' 
    [remote server] file:///tmp/webdriver-profile20120403-6182-1rd9z23/extensions/[email protected]/components/command_processor.js:10534:in `unknown' 
    [remote server] file:///tmp/webdriver-profile20120403-6182-1rd9z23/extensions/[email protected]/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 !!"' 
+0

某些框架實際上使_two_元素基本上相同。第一個是隱藏的,第二個是或不在。使用Firebug(和Firefinder?)來查找Selenium可以找到的所有元素。如果它在那裏,你需要改善你的搜索,或者找到所有符合要素,並過濾掉那些看不見的東西...... – 2012-04-03 06:57:25

+0

感謝您的回覆Slanec,但我試圖找出某種方式來訪問燈箱中的元素最初在燈箱出現後隱藏並可見。 – 2012-04-03 14:33:02

+0

這些對於WebDriver應該是可見的。你使用的是原始的Lightbox2還是一些衍生品?哪個硒版本?你能否提供一個簡單的測試用例? – 2012-04-03 15:04:06

回答

1

作爲臨時解決方法,您可以允許水豚看到隱藏的元素。我建議謹慎使用它,並添加一個特殊的標記,並且僅在某些情況下啓用它:

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

謝謝iafonov的回覆,但我是黃瓜新手,請你解釋我應該在哪裏放這個代碼? – 2012-04-04 06:48:32

+0

你應該把它放到env.rb中,然後在場景中添加@ ignore-hidden-elements標籤 – iafonov 2012-04-04 12:37:18

+0

感謝iafonov的幫助,你的解決方案適用於我的案例... 你節省了我很多時間。你能否解釋這是如何工作的,我只是想知道這個解決方案......? – 2012-04-04 14:25:22