0

I am using WebdriverIO to run a file-uploading .exe created with AutoIt.

I am running the script inside a browser.execute command. The file needs to run from the local drive and execute wd in Chrome browser. Here is the code :

this.open("https://smallpdf.com/word-to-pdf");
this.SubmitClick("//div[@class='l0v3m7-3 hIetmU']");
this.BrowserSleep(2000);
scr.runAutoItScript('C:\\test\\desktopApp\\autoit', 'fileUpload.exe')


//scr have the child process:
const { execFile } = require('child_process').execFile;
module.exports = {
  runAutoItScript(pathToScript, scriptName) {
    console.info(`\n> Started execution of ${pathToScript} / ${scriptName} ...`);

    execFile(`${pathToScript}/${scriptName}`, (error, stdout, stderr) => {
      if (error) {
        throw error;
      } else {
        console.info(`\n> Finished execution of ${scriptName}! | Output: ${stdout}`);
      }
    });
  }
}

1 Answer 1

1

I remember doing something like this in the past and I used NodeJS's child_process.execFile command. The documentation is heavy on child_process, so read carefully.

You should end up with something along the lines of:

const execFile = require('child_process').execFile;

let runAutoItScript = function(pathToScript, scriptName) {
  console.info(`\n> Started execution of ${scriptName} ...`);

  execFile(`${pathToScript}/${scriptName}`, (error, stdout, stderr) => {
    if (error) {
      throw error;
    } else {
      // > do something with the script output <
      console.info(`\n> Finished execution of ${scriptName}! | Output: ${stdout}`);
    }
  });
}

runAutoItScript('/this/is/a/valid/path', 'AwesomeScript.exe');

Next step would be to minify it and make it run inside browser.execute call.

You can find a lot of child_process examples online, just leverage the resources available to run the simplest script. Develop from there.

Sign up to request clarification or add additional context in comments.

6 Comments

Thanks for the answer and edit. I get : TypeError: execFile is not a function; both with browser.execute and without using it - directly calling node function given above. ------------- code: this.open("smallpdf.com/word-to-pdf"); this.SubmitClick("//div[@class='l0v3m7-3 hIetmU']"); this.BrowserSleep(1111); scr.runAutoItScript('C:\\test\\desktopApp\\autoit', 'fileUpload.exe')
@tanjs, can you update the question with the code snippet (format it accordingly) instead of using the comment section? Try to give some context for what you are trying to achieve, as an end-to-end flow.
I want to complete the file uploading when the web page has a drop file functionality (type='file' tag not present) - with selenium file selection diaglog box opened. The next step to give the file path and click ok button achieved with autoit script. stuck at the second step.
Thanks @Dan its resolved with: {} removal ------- const execFile = require('child_process').execFile;
Also browser.execute was not required - direct node function was called in code flow.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.