Issues getting CasperJS to upload image to file field - tried CasperJS fill() and PhantomJS uploadFile()

北慕城南 提交于 2019-12-05 07:56:43

Since you are filling and submitting successfully, try a Wait command on the click.

casper.then(function() {
    //+++ form fill here

    //waits 1 sec
    this.wait(1000, function() {
        this.click(x('//*[@id="content-wrapper"]//button/span'));
    });
});

Try this.

casper.thenOpen('about:blank', function(){
    this.evaluate(function(){
        var action = 'upload.php'
        var html = '<form action="'+action+'" method="post" enctype="multipart/form-data">'
        html += '<input type="file" name="files[]" multiple="multiple">'
        html += '<button type="submit">Submit</button>'
        html += '</form>'
        document.write(html)
    })
    this.fill('form',{
        'files[]': 'file.txt'
    }, true)
    this.waitFor(function(){
        var uri = casper.evaluate(function(){
            return document.documentURI
        })
        if ( 'about:blank' === uri ){
            return false
        }
        return true
    })
})
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!