0

我还没有找到一个明确的答案来在我的幻想框模式负载 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">

这会产生以下拒绝...

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

我需要添加/减去什么吗?

4

2 回答 2

1

css 定位器不正确。

div#fancybox-wrap

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

within("div.fancybox-wrap.fancybox-desktop.fancybox-type-iframe.fancybox-opened") do
    page.find_by_id('blah container').click
end
于 2012-12-04T18:54:14.567 回答
0

找到受此答案启发的更好答案

在 Poltergeist 中临时将 js_errors 设置为 false

但只有在您使用 poltergist 时才有效,该 poltergist 将 capybara 与 phantomjs 一起使用

# 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. 我们现在可以点击它
于 2015-11-11T07:09:26.757 回答