Search code examples
c#seleniumtestingdialogsendkeys

SendKeys to a windows file dialog


I want to send the string ABC to the input field of a windows file dialog. With this code line I can set the focus to the correct element. I see a blinken cursor.

var filedialogOverlay = drv.SwitchTo().ActiveElement();

But the following code doesn't write the string into the element.

Thread.Sleep(1000);
filedialogOverlay.SendKeys("ABC");

EDIT: The file upload prompt is shown by a website which I want to test. Because of black box testing I can't see the source code. Is there a tool to analyse the GUI?

When I right click the input element I get the following choices.

enter image description here


Solution

  • You can use the SendKeys.SendWait of Windows Form

    //Input the file path into the filename field:
    SendKeys.SendWait(longfilepath);
    //Input "Enter" key
    SendKeys.SendWait(@"{Enter}");
    

    https://msdn.microsoft.com/en-us/library/system.windows.forms.sendkeys.sendwait(v=vs.110).aspx