您好我需要使用cucumberJS和webdriverIO自动化网站。为此,我需要上传文件但该字段是隐藏的。例如:
<input type="file" id='uploadFile' style="display: none"'>
但是webdriver无法识别UI上的元素。
提前致谢...
答案 0 :(得分:0)
我得到了这个问题的解决方案。使用webdriverIO,我们可以执行javascript将样式显示从“none”更改为“block”。
client.execute(function() {
document.getElementById("element_id").style.display="block";
},function(err) {
client.uploadFile(localPath[,callback])
if(err){
console.log("Error "+err);
}
});
然后将文件上传到该字段,然后再次将显示更改为无。
答案 1 :(得分:0)
在webdriverIO v5中,通过使用本地文件路径作为参数调用type="file"
,将文件上传到.setValue()
的输入。不过,这似乎不适用于隐藏的输入,因为.setValue()
首先调用.clearValue()
,这将抛出Element could not be scrolled into view
。要解决此问题,请直接在元素上调用.addValue()
:
input.addValue(filePath);