Uploading files using WebdriverIO v5 with Microsoft Edge

Currently, I am in the process of running an automation test on SauceLabs using WebdriverIO version 5. One of the tests involves uploading a file to Microsoft Edge. Below is a snippet of the code for reference:

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

Although this code works perfectly with Chrome and Firefox, it encounters an error when attempting to run it on Microsoft Edge, displaying

Error: The uploadFile command is not available in Microsoft Edge
. It seems that the browser.uploadFile method is specific to Chrome. I have experimented with some alternative solutions, but most of them only function locally and not on a remote server like sauceLabs.

Is there any substitute for browser.uploadFile or perhaps a workaround that can be implemented to successfully upload files in the Microsoft Edge browser?

Answer №1

It appears that due to security reasons, the browser.uploadFile function is not supported in IE and Edge browsers.

I recommend trying out the code sample below as a workaround:

Firstly, locate the file upload element and then use sendkeys() method to set the path value in the control.

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

If the issue persists, you can attempt the following alternative example:

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

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

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

Reference:

Selenium how to upload files to Microsoft Edge

Note: You may need to adapt the provided code to fit your programming language.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Having trouble finding an element in a new tab on Chrome using Selenium Webdriver with Java

When you click the menu in the application, it automatically opens that page in a new tab and performs the action on the new tab String mainWindow = driver.getWindowHandle(); //when the element is clicked below, it opens in a new tab driver.findElement(B ...

Obtain information and receive alerts from Chrome console logs using Selenium through customized commands

Currently, I am attempting to extract logs from Chrome's console using Selenium with Python, but I am encountering some confusion as this is my first time working with it. While the code generally functions well and displays logs, I specifically need ...

The radio button cannot be interacted with as Selenium cannot find any other unique identifier for it

While examining the code of the button, I landed on this specific section: <input type="radio" name="chosen" value="UniqueNameExample"> I am attempting to locate an element within this code that I can interact with by c ...

transferring files without a user interface

Looking for a solution to upload a file by clicking on an element: <a class="gray_box" href="#">Choose world folder<span>Select the world folder, we'll do the rest</span></a> The issue arises when the file ...

Using Java's get() and getAttribute(), replace Selenium in C# for enhanced automation

Embarking on automation tasks in Selenium using Java, but now venturing into C# with selenium. Seeking guidance on how to translate the following Java logic into C# Visual Studio: Int count = driver.findelements(By.Name("radiobutton")).size(); For(int ...

When the Addmore button is clicked, a new text box with the same ID and class name will be generated and sent to the text box of ClientName

After clicking the add button, I encountered an issue where dynamically created text-boxes with the same id and class name were not allowing me to send text to the second or third text-box. List<WebElement> clientidtxt = driver.findElements(By.xpath ...

The Selenium script for running Chrome in headless mode is not functioning as expected

Version 106.0.5249.62 of Chrome the situation is...blah, blah, blah In a desperate attempt to create a script using selenium to snatch those certain files that would rock my world, I have taken the bold step of running chrome in headless mode. The gods lo ...

Discovering the optimum settings for Firefox and Chrome with selenium-jupiter

Is it possible to run Selenium tests with different options for Firefox and Chrome? I have tried setting the options for both browsers, but it doesn't seem to work. Running the same tests with both browsers is feasible, as well as setting options for ...

Tips for ensuring the success of a cucumber scenario

I have successfully integrated my framework with JIRA. Each time I run scripts, the framework checks the status of the test case in JIRA before executing it. If the test case has already passed, I currently handle it by using: throw new SkipException("&bs ...

Unable to start the AndroidDriver

This chunk of code is giving me trouble: WebDriver driver; driver = new AndroidDriver<MobileElement>(new URL("http://127.0.0.1:4723/wd/hub"), capabilities); I keep encountering this error: The type org.openqa.selenium.remote.service.DriverServi ...

Running two different wdio.config.js files consecutively

Is it possible to run two wdio.config.js files with different configurations, one after another? Here is how the first configuration file is defined in the code: const { join } = require('path'); require('@babel/register') exports.co ...

Using Selenium to interact with a numerical keyboard and pressing a button within the numerical scope

In my program, I have a numerical touchpad (1-9) that needs testing. The goal is to check if the user enters numbers that end in 1 to 9, such as 0.01, 0.33, or 4.46, the system should display a notification: "Invalid price". Numbers are only valid if they ...

Activate and choose options in a Drop-down menu based on the specific choice made in a different Drop-down menu

Upon selecting a value from the First Drop-down on the page, the Second Drop-down becomes enabled and loads corresponding values. In manual testing, after choosing a value in the First Drop-down, the page refreshes and the Second Drop-down becomes active ...

Leveraging Selenium in Python for extracting values contained within react-text elements代码

click here for image descriptionI'm currently using Python's Selenium library to extract data from the web for my projects. I am facing a challenge in extracting the telephone number (e.g., 04 81 68 30 45) from this specific HTML source code: &a ...

Switch the type and version of the browser using Selenium

In an attempt to change my user agent using the Selenium Webdriver, I have utilized the following code. However, it has come to my attention that Google Analytics is able to easily detect my browser and its version (specifically Firefox 54.0 in this case). ...

Using Python to interact with Selenium to click buttons that share the same name and ID

I am in need of an application that can click on the correct button when a specific option is available. I have identified a value that will change when the other option is not present. <form name="uniforma_NE" id="uniforma_NE" .=&qu ...

Is there a way to simulate mouseOver in IE8 and Firefox using WebDriver?

Issues with the moveToElement function in WebDriver have been noticed specifically in Firefox and IE, while working smoothly in Chrome browser. Below is the code snippet that I am currently using: Actions builder = new Actions(driver); builder.mov ...

Exploring the Differences Between Selenium-Webdriver with Java and TestNG versus Ruby

Currently, I have an automation suite using selenium-webdriver in Ruby with TestUnit. However, I have noticed that Java offers TestNg, which comes with many additional features. I am considering switching all my suites to Java and TestNg, but I also wond ...

Discovering WebElements nested within other WebElements using WebdriverJS

Looking at this HTML structure <div> <div> <p class="my-element"></p> </div> <div> <div> <div> <p class="the-text"> I want to retrieve this text</p> </div> </div> <div> ...

The attribute "parallel" set to "none" must be one of the following values: false, methods, tests, classes, or instances

I have set up a Maven project using Selenium WebDriver and integrated TestNG. However, when I validate my Maven project, an error message is displayed stating "Attribute "parallel" with value "none" must have a value from the list "false methods tests clas ...