不确定这是否有帮助......我们使用 nightwatch.js 来测试我们的应用程序并为单个文件提供 flowJS 上传按钮。
为了让它工作,我必须让隐藏文件输入既可见又启用。然后我可以用文件位置填充它并提交。
一些示例 nightwatch.js
//Re-enable traditional file-input
this.api.execute(function () {
document.getElementById('proof-upload-fallback').className = '';
document.getElementById('proof-upload-fallback').disabled = false;
});
this.api.setValue('//input[@id="proof-upload-fallback"]', require('path').resolve(filePath));
//Click upload
this.api.clickModalButton('Upload');
我们的 html 看起来像:
<input id="proof-upload-fallback" type="file" flow-btn="" ng-show="false" ng-disabled="true" class="ng-hide" />
<button flow-btn="" focus-input="focusButton">Select PDF<input type="file" style="visibility: hidden; position: absolute; width: 1px; height: 1px;"></button>
Submit: <button ng-click="ok()">Upload</button>
ng-click="ok" 负责处理flow.js,代码的重要部分是execute(),它是JS通过selenium驱动传递给实际的webapp...