PhantomJS 文件上传不适用于 XPath 表达式
PhantomJS file upload not working with XPath expression
我好像做不出来fileUpload work, I am using the script below but from the screenshot it is obvious that the file is not even selected in the form: 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');
这可能对您有所帮助
casper.then(function () {
var fileName = "/file path/";
this.evaluate(function (fileName) {
__utils__.findOne('input[type="file"]').setAttribute('value', fileName)
}, {fileName: fileName});
this.page.uploadFile('input[type="file"]', fileName);
console.log('Selecting file');
});
casper.then(function () {
console.log("Clicking on Upload to notebook check box");
this.click(x("Xpath of uploading button"));
console.log("Clicking on Submit icon");
});
我好像做不出来fileUpload work, I am using the script below but from the screenshot it is obvious that the file is not even selected in the form: 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');
这可能对您有所帮助
casper.then(function () {
var fileName = "/file path/";
this.evaluate(function (fileName) {
__utils__.findOne('input[type="file"]').setAttribute('value', fileName)
}, {fileName: fileName});
this.page.uploadFile('input[type="file"]', fileName);
console.log('Selecting file');
});
casper.then(function () {
console.log("Clicking on Upload to notebook check box");
this.click(x("Xpath of uploading button"));
console.log("Clicking on Submit icon");
});