【问题标题】:Uploading image using RobotFramework in hidden input element在隐藏的输入元素中使用 RobotFramework 上传图像
【发布时间】:2019-03-31 04:46:40
【问题描述】:

由于 hidden="hidden",我无法使用 Robot Framework 运行自动化测试。

请给我一些解决办法。

HTML 代码:

<a _ngcontent-c8="" class="browse cursor-pointer" tabindex="0">Browse</a>        
<input _ngcontent-c8="" id="file" style="border: 1px solid gray; cursor: pointer; margin: 5px; width: 300px;" accept=".png, .jpg, .jpeg, .gif, .tif, .tiff" type="file" hidden="hidden">

【问题讨论】:

  • 嗨@AshishKamble。这是我们的 html 代码 -

标签: selenium firefox robotframework selenium-firefoxdriver


【解决方案1】:

有一个解决方法 - 在与它交互之前通过 javascript 使元素可见:

Execute Javascript    document.getElementById('file'‌​).style.visibility='‌​visible'

更新:

如果您想设置一个不同于style 的属性,例如在本例中称为hidden 的自定义属性,您可以使用不同的js 方法:

Execute Javascript    document.getElementById('file'‌​).setAttribute('hidden') = 'new_value'

,其中 "new_value" 是您知道会使其可见的那个。

如果你想完全删除它,调用是

Execute Javascript    document.getElementById('file'‌​).removeAttribute('hidden')

【讨论】:

  • 仍然看不到
【解决方案2】:

如果有人像我一样还在为 SyntaxErrors 苦苦挣扎,下面是适用于我的 setAttribute 的正确语法:

Execute Javascript document.getElementById('file'‌​).setAttribute('attributeName', 'attributeValue');

如果你没有 id 属性:

Execute Javascript document.getElementsByClassName('file'‌​)[0].setAttribute('attributeName', 'attributeValue');

仅供参考:getElementsByClassName 方法返回一个元素数组。

【讨论】:

    猜你喜欢
    • 2020-05-19
    • 2023-02-10
    • 1970-01-01
    • 1970-01-01
    • 2020-01-27
    • 1970-01-01
    • 1970-01-01
    • 2013-09-19
    • 1970-01-01
    相关资源
    最近更新 更多