Html 如何找到带水豚的灯箱/fancybox

Html 如何找到带水豚的灯箱/fancybox,html,ruby,fancybox,cucumber,capybara,Html,Ruby,Fancybox,Cucumber,Capybara,我还没有找到一个在我的fancybox modal-loaded Web应用程序中查找和操作元素的明确答案 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 fanc

我还没有找到一个在我的fancybox modal-loaded Web应用程序中查找和操作元素的明确答案

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">

有什么需要添加/减去的吗?

css定位器不正确

拥有

div#fancybox-wrap
表示id为“fancybox wrap”的div。基于html,“fancybox包装”是一个类。因此,您实际上想要(注意将“#”更改为“.”):


从这个答案中找到了一个更好的答案

但只有当你使用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
它有什么作用

  • 试着点击我们真正想要的东西
  • 如果现在不行,我们知道覆盖层挡住了去路
  • 我们现在可以点击它了

  • 你能提供这个页面的HTML或者一个重现问题的页面吗?我想是这样的。谢谢贾斯汀!Hacky
    page.find('html')。单击
    可以关闭它。
    within("div.fancybox-wrap.fancybox-desktop.fancybox-type-iframe.fancybox-opened") do
        page.find_by_id('blah container').click
    end
    
    # 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