我在自动化测试中一直使用相同的功能上传文件:
var path = require('path');
//the file to upload
fileToUpload,
//this is variable that inserts the path to find file to upload
absolutePath = path.resolve(__dirname, fileToUpload);
//inserts the path
uploadPathLink.sendKeys(absolutePath);

<button class="btn btn-select" data-bind="click: assosiateLogoImage">
&#13;
我的html中的上传表单如下所示:
<form id="uploadForm" action="https://iplan.preview.s3.amazonaws.com/" enctype="multipart/form-data" target="uploadIFrame" method="post">
<div class="file-input" data-bind="css: {'ie': isIE}">
<input id="logoFile" type="file" data-bind="event:{ 'change': handleLogoSelection }" name="file">
</div>
</form>
&#13;
上传表单会打开然后挂起。我知道该文件的路径是有效的,因为它是我在应用程序的其他部分上传的相同文件,任何想法?
答案 0 :(得分:0)
问题是我发送了错误元素的绝对路径,应该看起来像这样:
var path = require('path');
//the file to upload
fileToUpload,
//this is variable that inserts the path to find file to upload
absolutePath = path.resolve(__dirname, fileToUpload);
//inserts the path
$('input[type="file"]').sendKeys(absolutePath);
};