我似乎无法制作fileUpload工作中,我正在使用下面的脚本,但从屏幕截图中可以明显看出,该文件甚至没有以以下形式选择: Screenshot
casper.thenOpen('https://encodable.com/uploaddemo/', function () {
this.waitForSelector(x('//input[@type="file"]'), function () {
casper.page.uploadFile(x('//input[@type="file"]'), '/Users/stratos/Desktop/IMG_1344.png');
});
});
casper.then(function () {
this.wait(5000, function () {
this.capture('test/integration/screenshots/uploadTest.png');
});
});
测试运行良好,没有错误,所以我不知道发生了什么:(
我正在使用 PhantomJS 2.1.1 和 CasperJS 1.1.0-beta5
如果测试按下“上传”按钮,则会触发页面验证,因为没有选择文件。
最佳答案
page.uploadFile()
是 PhantomJS 函数,不支持 CasperJS 使用 XPath 表达式。它只接受 CSS 选择器作为简单的字符串:
casper.page.uploadFile('input[type="file"]', '/Users/stratos/Desktop/IMG_1344.png');
关于javascript - PhantomJS 文件上传不适用于 XPath 表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36454466/