【问题标题】:Can't fill in the Hidden text area element无法填写隐藏的文本区域元素
【发布时间】:2018-05-29 14:05:07
【问题描述】:

F1,需要一些关于 隐藏元素 使用 Robotframework 的帮助或提示。
问题在于要填充文本区域中的任何文本,我需要将文本区域的状态从 display:none; to display:block; 更改为

Needed text area for input

Code that I see from WebDev Tool

代码本身:

<div class="col-md-12">
<div class="cazary" style="width: 664px;">
    <div class="cazary-commands-wrapper">
        <ul class="cazary-commands-list">
            <li unselectable="on" title="Size" class="cazary-command-fontsize">Size</li>
        </ul>
        <ul class="cazary-commands-list">
            <li unselectable="on" title="Foreground Color" class="cazary-command-forecolor">Foreground Color</li>
        </ul>
        <ul class="cazary-commands-list">
            <li unselectable="on" title="Background Color" class="cazary-command-backcolor">Background Color</li>
        </ul>
        <ul class="cazary-commands-list">
            <li unselectable="on" title="Remove Format" class="cazary-command-removeformat">Remove Format</li>
        </ul>
    </div>
    <iframe class="cazary-edit" src="javascript:" style="height: 39px;"></iframe>
    <textarea id="summernote" class="required-preview field cazary-source" placeholder="Tell us all about your Advertisement. This description will be prominently displayed in your Advertisement notice. Feel free to adjust the fonts and background colour too." name="observations" cols="50" rows="10" style="display: none;"></textarea>
</div>

我的 Robotframework 代码尝试:

Select Frame      //iframe[@class="cazary-edit"]
# First try
Input text      //textarea[@id="summernote"]    ${UniversalVariableforName}
# Second try
Input text      //iframe[@class="cazary-edit"]    ${UniversalVariableforName}
# Third try
Input text      //div[@class="cazary"]//iframe[@class="cazary-edit"]    ${UniversalVariableforName}
# Fourth try
Input text      //body[@class="empty"]    ${UniversalVariableforName}
# Fifth try
Input text      //iframe[@class="cazary-edit"]//body[@class="empty"]    ${UniversalVariableforName}

返回的错误: image

可能有Execute Javascript关键字的解决方案?

【问题讨论】:

  • 文本区域在 iframe 之外,而且它是隐藏的。你无法与之互动。
  • 您可以手动输入值吗?
  • 嗨@Murthi,是的,我可以手动填写指定文本区域中的任何信息
  • 请不要发布错误图片。花点时间将它们正确复制、粘贴并格式化到您的问题中。
  • 如果您能够手动填写,很可能还有另一个元素实际上正在接受输入,然后通过 JS 将值传播到 textarea。找到另一个并定位它 - 通过操纵 textarea 的显示,您的测试将无法复制真实的用户交互。

标签: python selenium iframe robotframework selenium2library


【解决方案1】:

相关&lt;textarea&gt;不在&lt;iframe class="cazary-edit"&gt;之外。因此我们不需要切换到 &lt;iframe&gt;

要将文本发送到 Input 字段,您可以尝试:

  • xpath 用作:

    "//textarea[@class='required-preview field cazary-source' and @id='summernote']"
    
  • Click 首先是 Input 字段。

  • 接下来是 Clear Input 字段。
  • 最后尝试发送文本。

更新:

由于相关textareastyle属性设置为"display: none;",我们必须通过JavascriptExecutor更改为"display: block;" 然后发送文本。

Python 示例代码:

driver.execute_script("document.getElementById('ID').style.display='block';") 

【讨论】:

  • 嗨@DebanjanB,我试过你的解决方案,不幸的是它没有帮助。
    但是我观察到需要的元素是隐藏的,所以我搜索了一段时间,发现了改变 DOM 元素状态的想法,在我的情况下 textarea ,应该将 style="display: none;" 更改为 display:block;
    也尝试了这个想法,但没有任何问题,返回失败。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-03-07
  • 2017-05-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多