Не удается загрузить файл с PhantomJS - PullRequest
0 голосов
/ 07 мая 2018

Вот мой код:

setTimeout(function () {
    console.log("Page opened, ready to upload file.  Status is", status);
    var inputEl = document.querySelectorAll("input[type=file]")[0];
    console.log("Upload=" + JSON.stringify(inputEl)); // <---- NULL here
    page.upload(inputEl, 'C:/temp/1.JPG'); // <--- so this throws error
    page.evaluate(function () {
                var inputEl = document.querySelectorAll("input[type=file]")[0]; // <--- Not NULL here but...
                page.upload(inputEl, 'C:/temp/1.JPG'); // <--- cannot call page.upload from inside page.evaluate
    });
}, 5000);

Как указано в комментарии, проблема в том, что я не могу заставить программу загрузить файл (изображение на самом деле), что может быть не так в моем коде?

UPDATE

Вот еще один код, который я пробовал:

inputEl = page.evaluate(function(s) {
                  console.log("Selector=" + s);
                  var el = document.querySelectorAll(s)[0];
                  //console.log("(1)Upload=" + JSON.stringify(el));
                  return el;
              }, 'input[type=file]');
              console.log(inputEl.tagName); // output = INPUT
              console.log(inputEl.id); // output = id of element, OK
              page.uploadFile(inputEl.id, "C:\\temp\\1.JPG");
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...