0

I am running an automation test in sauceLabs using webdriverio v5. I want to run a test which is uploading a file to msedge. Below is the sample code for the same.

const path = require('path');
const filePath = path.join(__dirname, 'path/to/your/file');
const remoteFilePath = browser.uploadFile(filePath);
$('upload file input selector').setValue(remoteFilePath);

This code works fine with chrome and firefox but when i try to run the same in msedge is gives Error: The uploadFile command is not available in msedge. Seems like browser.uploadFile only works for chrome. i have tried various other things but the solutions works mostly on local and not on remote server like sauceLabs.

Is there any alternative for browser.uploadFile or any workaround which can be used to upload the file in msedge browser?

Makarand Patil
  • 1,001
  • 1
  • 8
  • 15

1 Answers1

1

Looks like for security reasons, browser.uploadFile is not available to use for IE and Edge browsers.

I suggest you try to make a test with the code sample below.

It first finds the file upload element and then it uses sendkeys() to set the path value in control.

// fetch the element
WebElement input = driver.findElement(By.XPath("//input[@type='file']"));
// send file path keys
input.sendKeys(path);

If the issue persists then you can try the below example.

// fetch the element
WebElement input = driver.findElement(By.XPath("//input[@type='file']"));

// run JS to reveal the element
JavascriptExecutor executor = (JavaScriptExecutor)driver;
executor.executeScript("arguments[0].style.display = 'block';", input);

// send file path keys
input.sendKeys(path);

Reference:

Selenium how to upload files to Microsoft Edge

Note: You may need to convert the above code into your developing language.

Deepak-MSFT
  • 10,379
  • 1
  • 12
  • 19
  • Thanks @Deepak-MSFT, I have already tries the code from the reference link that you have provided. In webdriverio v5 we have setValue instead on sendKeys. But it gives the error 'path not found' as it is local path and we are running the tests on sauceLabs which is remote server and can't access the path. In chrome and Firefox we have UploadFile which uploads the file on remote server and return the path which is then passed to setValue – Makarand Patil Mar 17 '20 at 07:48
  • I think this thing is not possible with IE and Edge legacy browsers due to some security reasons. If you are available to use the new Edge Chromium browser then I suggest you make a test with it. As it is based on chromium-browser engine your code should work with it. – Deepak-MSFT Mar 17 '20 at 09:30
  • Did you try https://webdriver.io/docs/api/browser/keys.html which seems to be near equivalent to sendkeys? – Raju Mar 17 '20 at 16:05