Microsoft Edge WebDriver - unable to upload file - sendKeys not working at "input type=file"

External Issue #7194303

Details

Author
Milos S.
Created
Apr 13, 2016
Privacy
This issue is public.
Reports
Reported by 18 people

Sign in to watch or report this issue.

Steps to reproduce

using selenium I’m unable to upload file in Edge. IE works fine with the same code. Follow steps below to reproduce issue:

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.edge.EdgeDriver;
public class UploadFileEdgeTest {
    WebDriver driver;
    @Before
    public void setUp() throws Exception {
        System.setProperty("webdriver.edge.driver", "pathToDriver/MicrosoftWebDriver.exe");
        driver = new EdgeDriver();
        driver.get("http://the-internet.herokuapp.com/upload");
    }
    @After
    public void tearDown() throws Exception {
        driver.quit();
    }
    @Test
    public void uploadFile() {
        driver.findElement(By.id("file-upload")).sendKeys("pathToFile");
        driver.findElement(By.id("file-submit")).click();
    }
} 

Attachments

0 attachments

    Comments and activity

    • Microsoft Edge Team

      Changed Assigned To to “Rick J.”

      Changed Assigned To from “Rick J.” to “Ibrahim O.”

      Changed Assigned To to “Rick J.”

      Changed Assigned To to “Mara P.”

      Changed Status to “External”

    • This is a duplicate of a backlogged work item to implement. Normally the value of an input type="file" is not settable except by the browser itself after the user opens the Browse dialog and selects a file.

    • Can you please link the ticket that this issue duplicates so that we can track it’s progress?

    • Can anyone let me know the workaround for this.I am facing the same issue.Not able to send the path of the file through send keys.

    • Is there any work-around for this at this moment? Java-script/Sendkeys do not work on edge driver for uploading a file.

    • Any possible work-around ?

    • As of now, this still appears to be an issue. Lack of this functionality causes inability to test file upload scenarios in Edge. Are there any updates or suggested temporary workarounds for this issue?

    • Any workaround available?

    • Unfortunately there is currently no workaround for this issue but we are actively working on a fix for this. A possible ‘workaround’ is to .Click() on the element and selecting the file manually via the file picker. I understand this is not a viable fix for any automated test suites and I’m looking to solve this issue as soon as possible.

       

      The bug we are tracking for this is internal and thus not visible externally, I will try to update all dupes of this bug when it is fixed.

    • Microsoft Edge Team

      Changed Assigned To to “Stanley H.”

    • You can workaround with AutoIT .

      using System;
      using System.Collections.Generic;
      using System.Linq;
      using System.Text;
      using System.Threading;
      using System.Threading.Tasks;
      using OpenQA.Selenium;
      using OpenQA.Selenium.Edge;
      using OpenQA.Selenium.Chrome;
      using OpenQA.Selenium.IE;
      using OpenQA.Selenium.Firefox;

      using System.IO;
      using System.Data;
      using System.Collections;

      using AutoIt;

      namespace OpenFileSelenium.OfdSelenium
      {
      public class OfdSelenium
      {
      static void Main(string[] args)
      {
      Automation auto = new Automation();
      Thread oThread = new Thread(new ThreadStart(auto.DoAutomationEdge));
      oThread.Start();
      FileMontior fmMonitor = new FileMontior();
      Thread fmThread = new Thread(new ThreadStart(fmMonitor.SetFileName));
      Console.WriteLine(“Waiting for Open…”);
      Thread.Sleep(20000);
      Console.WriteLine(“Start File Name…”);
      fmThread.Start();
      oThread.Join();
      fmThread.Join();

          }
      
      }
      

      public class FileMontior
      {
      public void SetFileName()
      {
      int _numproc = AutoIt.AutoItX.WinWaitActive(“Open”);
      AutoIt.AutoItX.Send(“C:\borrr\mage_test.jpg”);
      AutoIt.AutoItX.Send(“{ENTER}”);
      }
      }

      public class Automation
      {
      public void DoAutomationEdge()
      {
      EdgeOptions options = new EdgeOptions();
      options.PageLoadStrategy = EdgePageLoadStrategy.Normal;
      IWebDriver driver = new EdgeDriver(AppDomain.CurrentDomain.BaseDirectory, options);
      TimeSpan DriverTimeout = TimeSpan.FromSeconds(100);
      driver.Url = "https://images.google.com/";

            var theanchor = driver.FindElements(By.TagName("a")).Where(a => a.GetAttribute("aria-label") == "Search by image").FirstOrDefault();
            var indexanchor = driver.FindElements(By.TagName("a")).IndexOf(theanchor);
            string scriptex = "document.getElementsByTagName('a')[" + indexanchor + "].click()";
            ((IJavaScriptExecutor)driver).ExecuteScript(scriptex);//.ToString();
            var anchors = driver.FindElements(By.TagName("span"));
            var uptheanchor = anchors.Where(a => a.Text == "Upload an image").FirstOrDefault();
      
            var indexupanchor = anchors.IndexOf(uptheanchor);
            scriptex = "google.qb.ti(true); return false"; //href="javascript: void(0)">Upload an image
      

      "//"document.getElementsByTagName(‘span’)[" + indexupanchor + "].click()";
      ((IJavaScriptExecutor)driver).ExecuteScript(scriptex);//.ToString();

            ((IJavaScriptExecutor)driver).ExecuteScript("document.getElementById('qbfile').click()");
            Console.Write("FIN de DoAutomation");
      
        }
      

      }
      }

    • this is now fixed in an internal build and will be available publicly soon.

    You need to sign in to your Microsoft account to add a comment.

    Sign in