在隐藏的输入元素中使用 RobotFramework 上传图像
Uploading image using RobotFramework in hidden input element
由于 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">
有一个解决方法 - 在与元素交互之前通过 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')
如果有人像我一样还在为 SyntaxErrors 苦苦挣扎,这里是适合我的 setAttribute 的正确语法:
Execute Javascript document.getElementById('file').setAttribute('attributeName', 'attributeValue');
如果您没有 id 属性:
Execute Javascript document.getElementsByClassName('file')[0].setAttribute('attributeName', 'attributeValue');
仅供参考:方法 getElementsByClassName return 元素数组。
由于 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">
有一个解决方法 - 在与元素交互之前通过 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')
如果有人像我一样还在为 SyntaxErrors 苦苦挣扎,这里是适合我的 setAttribute 的正确语法:
Execute Javascript document.getElementById('file').setAttribute('attributeName', 'attributeValue');
如果您没有 id 属性:
Execute Javascript document.getElementsByClassName('file')[0].setAttribute('attributeName', 'attributeValue');
仅供参考:方法 getElementsByClassName return 元素数组。