'How to submit file input using javascript - Selenium?
i use C# Selenium in my App, i click on file input and (open window) file dialog show up. I need to pass filepath and then hit enter (return) key.
Requirement: work even if current user is signed out, desktop is locked, RDP session closed
- Selenium built-in SendKeys did not work at all.
- Windows.Forms.SendKeys.SendWait() work not so excatly, path submit is ok, in order to hit enter, process wait for user session. Nuget -
- InputSimulator / WinApi - UAC (UIPI) access denied
Any possibility to submit file without opening dialog in javascript ?
Thanks
Example using Selenium
var button = web.FindElementByXPath("//span[@class='upload']");
button.Click();
Not working
button.SendKeys("path"); //not input element
Windows.Forms.SendKeys.SendWait("..."); //not working for closed user session
InputSimulator.SimulateTextEntry("path"); //access denied because of Windows UIPI
Solution 1:[1]
If there is a file input (<input type='file'/>) somewhere in the dom, you can do something like this:
https://www.selenium.dev/documentation/webdriver/remote_webdriver/#local-file-detector
IWebElement upload = driver.FindElement(/*select the <input> element*/);
upload.SendKeys(filepath); // as string
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Darkproduct |
