2012-12-04 53 views
0

我還沒有找到一個明確的答案來查找和操縱我fancybox模式載入webapp中的元素。如何找到與水豚燈箱/ fancybox

within("div#fancybox-wrap.fancybox-desktop.fancybox-type-iframe.fancybox-opened") do 
    page.find_by_id('blah container').click 
end 

這裏是一個更大的背景下所要求

<div class="fancybox-wrap fancybox-desktop fancybox-type-iframe fancybox-opened" style="width: 415px; height: auto; display: block; position: fixed; top: 20px; left: 467px; opacity: 1; overflow: visible;"> 
<div class="fancybox-skin" style="padding: 15px;"> 
    <div class="fancybox-outer"> 
     <div class="fancybox-inner" style="width: 385px; height: 229px; overflow: hidden;"> 
      <iframe class="fancybox-iframe" name="fancybox-frame" frameborder="0" hspace="0" scrolling="auto" src="index.php?module=Yadda&amp;action=[where I wan to be]&amp;popup=Y&amp;id=[unique]&amp;width=1010&amp;height=600"> 
       [the stuff I want to access] 
      </iframe> 
     </div> 
    </div> 
<div title="Close" class="fancybox-item fancybox-close"> 

這會產生以下拒絕......

Unable to find css "div#fancybox-wrap.fancybox-desktop.fancybox-type-iframe.fancybox-opened" (Capybara::ElementNotFound) 

請問有什麼需要加/減?

+0

能否請您提供的的HTML頁面或重現問題的頁面? –

+0

增加更多信息 – TangibleDream

回答

1

css定位器不正確。

div#fancybox-wrap 

意味着ID 「的fancybox纏繞」 一個div。基於html,「fancybox-wrap」是一個類。因此,你真正想要的(注意,「#」改爲「」):

within("div.fancybox-wrap.fancybox-desktop.fancybox-type-iframe.fancybox-opened") do 
    page.find_by_id('blah container').click 
end 
+0

我認爲那樣做了。謝謝Justin! – TangibleDream

0

找到一個更好的答案,是由這個答案

Temporarily set js_errors to false in Poltergeist

的啓發,但如果只會工作您正在使用幻燈片使用水豚的poltergist

# think about it. this is what you do in real life 
# Try to click thing you actually want. get caught by the the overlay then click to dismiss it away 
tried_before = false 
    if page.has_css?('#autostart') 
    begin 
     click_link "Insurance", match: :first 
    rescue Capybara::Poltergeist::MouseEventFailed 
     # close the fancy box 
     if tried_before 
     raise e 
     end 
     find('#fancybox-close').click 
     retry 
    end 
    end 
end 

它是做什麼的?

  1. 嘗試點擊我們其實是想
  2. 的事情,如果它不能現在我們知道,罩面層的方式
  3. 我們可以單擊它現在