如何找到嵌套在I帧中的元素?

时间:2012-12-11 19:44:48

标签: html ruby selenium cucumber capybara

我希望测试一封电子邮件的正文。

它使用一个位于3个i帧深度的FCK编辑器。

<...name="fancybox-frame"...>
    <iframe>
        <iframe>
             <body>H E R E  I S  W H A T   I   W A N T  T O   A C C E S S</body>
        </iframe>
    </iframe>
</[fancybox-frame]>

除了含糊不清的乐趣之外,我如何多次在帧内使用。

如果我用这个......

within_frame('fancybox-frame') do
fill_in('frm_subject', :with => eventname + ' email')
within_frame('iframe[id="frm_message___Frame"]') do
  within_frame('iframe') do
    fill_in('body', :with => 'Event email for ' + now.to_s)
  end
end

我明白了......

      switchFrame execution failed;
   INVALID_EXPRESSION_ERR: DOM XPath Exception 51 (Selenium::WebDriver::Erro
r::WebDriverError)
  ./features/step_definitions/RCST08_steps.rb:96:in `block (2 levels) in <to
p (required)>'
  ./features/step_definitions/RCST08_steps.rb:94:in `/^select a message to s
end\.$/'
  features\RCST08.feature:26:in `And select a message to send.'

有什么想法吗?

1 个答案:

答案 0 :(得分:1)

Selenium无法解决帧内的任何内容(&lt; IFRAME&gt;或&lt; FRAME&gt;),直到您“切换”它为止。在Ruby绑定中,这就是within_frame(...) do ... end的作用。你似乎是你想成为的一个框架之外的一个框架。你需要更像这样的东西:

within_frame('fancybox-frame') do
  fill_in('frm_subject', :with => eventname + ' email')
  within_frame('iframe[id="frm_message___Frame"]') do
    within_frame('...name of outer iframe...') do
      within_frame('...name of inner iframe...') do
        fill_in('body', :with => 'Event email for ' + now.to_s)
      end
    end
  end
end
相关问题