SeleniumHQ / selenium

A browser automation framework and ecosystem.
https://selenium.dev
Apache License 2.0
30.7k stars 8.19k forks source link

File upload doesn't work for RemotewWebDriver #9350

Closed VitaliiDolotov closed 3 years ago

VitaliiDolotov commented 3 years ago

🐛 Bug Report

File upload is not working using RemoteWebDriver. It is working fine running locally but fails on Remote.

Last working version 4.0.0-alpha05 Stop working since 4.0.0-alpha07 Still not working in 4.0.0-beta2

Unable to upload file: System.NotImplementedException: unknown command: unknown command: session/eaee033d03861677627f084357ea877a/se/file
   at OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(Response errorResponse)
   at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
   at OpenQA.Selenium.Remote.RemoteWebDriver.InternalExecute(String driverCommandToExecute, Dictionary`2 parameters)
   at OpenQA.Selenium.Remote.RemoteWebElement.Execute(String commandToExecute, Dictionary`2 parameters)
   at OpenQA.Selenium.Remote.RemoteWebElement.UploadFile(String localFile)
   at OpenQA.Selenium.Remote.RemoteWebElement.SendKeys(String text)
   at SeleniumExtras.PageObjects.WebElementProxy.SendKeys(String text)

To Reproduce

driver.FindElement(By.Id("upload")).SendKeys(file);

Expected behavior

File uploaded successfully

Test script or set of commands reproducing this issue

                var chromeOptions = new ChromeOptions();

                chromeOptions.AddArguments("headless", "--window-size=1920,1080", "--safebrowsing-disable-download-protection");

                chromeOptions.AddUserProfilePreference("download.default_directory", "/home/selenium/Downloads");
                chromeOptions.AddUserProfilePreference("download.prompt_for_download", false);
                chromeOptions.AddUserProfilePreference("download.directory_upgrade", true);
                chromeOptions.AddUserProfilePreference("safebrowsing.enabled", false);

                chromeOptions.SetLoggingPreference(LogType.Browser, LogLevel.All);
                var driver = new RemoteWebDriver(new Uri(Browser.HubUri), chromeOptions);

                driver.Navigate().GoToUrl("<URL>");

                IAllowsFileDetection fileDetectionDriver = (IAllowsFileDetection)driver;
                fileDetectionDriver.FileDetector = new LocalFileDetector();

                var file = "<File_Path>";

                driver.FindElement(By.Id("upload")).SendKeys(file);

Environment

OS: Windows 10 Browser: Chrome Browser version: 89.0.4389.114 Browser Driver version: Selenium.WebDriver.ChromeDriver -Version 89.0.4389.2300 Language Bindings version: C# Selenium Grid version (if applicable): selenoid 1.10.3

Notes

There is a separate bug (https://github.com/SeleniumHQ/selenium/issues/8524) that may be related but there are no steps how to deal with the above behavior.

diemol commented 3 years ago

Hey @VitaliiDolotov, please report this issue to the Selenoid project.

VitaliiDolotov commented 3 years ago

For future refer https://github.com/aerokube/selenoid/issues/1079

StanislavKharchenko commented 3 years ago

@diemol In the refered selenoid issue was saying that there usage of API /se/file which doesn't exist in W3C standard. As I know Selenium 4 is now fully w3c, so maybe at your side need to create some wrapper which will be fully compatible with w3c and workable with file upload for remote driver?

jimevans commented 3 years ago

@StanislavKharchenko The Selenoid issue is not entirely accurate. The /session/{sessionId}/se/file end point is fully compliant with the W3C spec. The spec allows “extension commands” when used with a so-called “vendor prefix.” The Selenium project has chosen “se” as its vendor prefix and is free to introduce whatever custom end points or commands it cares to under thar name space. There may be a bug in Selenium’s server component, but I believe that is indeed what #8524 was referring to. If Selenoid’s intermediary node implementation chooses not to implement the Selenium extension command, that’s their choice, and they’re welcome to make that. They would also be correct in claiming their implementation to be “spec compatible,” but that functionality would then not work with Selenium.