在HTML编辑器中插入文本

问题描述 投票:0回答:1

我正在做一个测试场景,我必须用功能中传递的字符串填充一个HTML编辑器字段。我的问题是在能够输入这些信息。我使用Cucumber与Capybara在Ruby on Rails上测试一个系统。

按照我所面临的HTML。

<div class="x-component x-html-editor-input x-box-item x-component-default" id="htmleditor-1324-inputCmp" style="margin: 0px; right: auto; left: 0px; width: 419px; top: 34px;">
<iframe id="htmleditor-1324-inputCmp-iframeEl" name="ext-gen1890" frameborder="0" src="about:blank" class="x-htmleditor-iframe" style="width: 100%; height: 150px;">
<html>
<head>
<style type="text/css">body{border:0;margin:0;padding:3px;direction:ltr;min-height:144px;box-sizing:border-box;-moz-box-sizing:border-box;-webkit-box-sizing:border-box;cursor:text;background-color:white;font-size:12px;font-family:Helvetica}
</style>
</head>
<body style="font-size: 12px; font-family: helvetica, arial, verdana, sans-serif; background-image: none; background-repeat: repeat; background-color: rgb(255, 255, 255); color: rgb(0, 0, 0); background-attachment: fixed; cursor: text;">
​</body>
</html>
</iframe>
</div>

我所面临的HTML: <body> 就是在屏幕上插入文字的地方。下面是屏幕上字段的打印。https:/i.stack.imgur.comyjdV3.png。

在我的page.rb中,我有以下方法。

class SR_wallet
    include Capybara::DSL
    def find_solicitation_description (solicitation_description)
        find('iframe[id="htmleditor-1324-inputCmp-iframeEl"]').set solicitation_description
    end
end

我的步骤是:

And("I fill in the Request field with: {string}") do |solicitation_description|
  @solicitation_description = solicitation_description
  iframe = find('iframe[id="htmleditor-1324-inputCmp-iframeEl"]').click
  within_frame (iframe) do
    @SR_wallet.find_solicitation_description(@solicitation_description)
  end
end

我可以点击字段,但我不能在里面插入信息。在错误的情况下,它总是返回给我说找不到元素ID.我尝试了很多方法,但最终还是停留在当前的表单中,因为我无法进步,所以我总是以同样的错误告终。

 Unable to find css "iframe[id=\"htmleditor-1324-inputCmp-iframeEl\"]" (Capybara::ElementNotFound)
cucumber capybara capybara-webkit
1个回答
1
投票

你需要把上下文移到iframe里面,否则你将无法访问任何东西。 另外假设页面上只有一个这样的字段,你最好通过类来搜索,而id看起来像是随机生成的。 这也假设了 body 元素是contentEditable--在你的HTML中不显示,但不允许用户以其他方式输入(除非有一大堆JS处理这些,否则你就倒霉了)。

within_frame(class: 'x-htmleditor-iframe') do
  find('body').set solicitation_description
end
© www.soinside.com 2019 - 2024. All rights reserved.