2

I know the default answer to handling explorer.exe is to use AutoIT, but AutoIT utilizes Java Runtime to use the exported .exe to upload the file and close the dialog. My tests are all in Protractor since this is an AngularJS app.

The selectFile function is:

selectFile: function(image) {
  var path = require('path');
  var image_path = path.resolve(__dirname, image);

  this.uploadButton.click();
  this.uploadButton.sendKeys(image_path);
}

I've run my full suite of tests in Chrome, Firefox, and IE11. Chrome and Firefox just leave the file upload window open and carry on their tests in the background. IE absolutely will not continue after clicking the upload button. The dialog box must be dealt with somehow, but my test can't even get to this.uploadButton.sendKeys(image_path); with that window open.

Is there a way to kill that File Upload box via Javascript, whether it be by process id or something else?


More detailed info on my attempts at getting around this are on my Stack Overflow question from before I knew this site existed. Since you all are more specialized, perhaps I can get more / different answers here, too.

1

You can't interact with the native OS file browser dialog directly, but we do some magic so that if you call WebElement#sendKeys("/path/to/file") on a file upload element, it does the right thing. Make sure you don't WebElement#click() the file upload element, or the browser will probably hang. Source - Selenium WebDriver Wiki.

Protractor uses WebDriverJS (source). Check out the Protractor sendKeys() API documentation.

  • I do use sendKeys() in my test as it stands. I suppose the issue with our app is that we must click the upload button to trigger the file upload. When this page was first introduced, we tried just this.uploadButton.sendKeys(image_path); but it wouldn't actually upload anything without the initial click of the image upload button. – ItsASine May 18 '15 at 19:39
  • 1
    Talk to your developers and find out what JS event needs to be triggered and then emulate it. – Ardesco Sep 10 '15 at 13:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.