使用 CucumerJS 将文件上传到 WedriverIO 中的隐藏字段

Pri*_*ank 1 webdriver cucumber node.js selenium-webdriver cucumberjs

嗨,我需要使用cucumberJS 和webdriverIO 自动化一个网站。为此,我需要上传一个文件,但该字段是隐藏的。例如 :

<input type="file" id='uploadFile' style="display: none"'>
Run Code Online (Sandbox Code Playgroud)

但 webdriver 无法识别 UI 上的元素。

提前致谢...

小智 8

在 webdriverIO v5 中,文件type="file"通过.setValue()使用本地文件路径作为参数调用它们来上传到输入。不过,这似乎不适用于隐藏的输入,因为.setValue()第一个调用.clearValue()会抛出Element could not be scrolled into view. 要解决此问题,请.addValue()直接调用该元素:

input.addValue(filePath);
Run Code Online (Sandbox Code Playgroud)

相关API文档:https : //webdriver.io/docs/api/element/addValue.html