PhantomJS - onFilePicker()



onFilePicker () 回调用于上传文件。当用户想要上传文件时,会调用此回调。

语法

其语法如下 -

page.onFilePicker = function(oldFile) { } 

示例

var wpage = require('webpage').create(); 
wpage.onFilePicker = function(oldFile) { 
   console.log('Entering file picker callback'); 
   console.log(oldFile); 
} 
wpage.open("https://127.0.0.1/tasks/file.html", function(status) { 
   console.log(status); 
   
   wpage.evaluate(function() { 
      var fileUp = document.querySelector("#fileToUpload"); 
      var ev = document.createEvent("MouseEvents"); 
      ev.initEvent("click", true, true); 
      fileUp.dispatchEvent(ev); 
   });  
});

以上程序会生成以下 输出

Success 
Entering file picker callback 
phantomjs_webpage_module_events_callbacks.htm
广告