0

We have a complicated Java/Selenium framework at my job and I am having a hard time uploading an image wit sendKeys() in a remote server. The code works locally, but not on our Selenoid server. I've done lots of research and found out this was stemming from W3C standards but I'm assuming it is fixed now.

Here is a piece of our code:

protected void sendKeysUploadPhoto(By by, String path) {
        executeScript("arguments[0].style.display = 'block';", driver.findElement(by));
        ((RemoteWebDriver) driver).setFileDetector(new LocalFileDetector());
        try {
            driver.findElement(by).clear();
            driver.findElement(by).sendKeys(path);
        } catch (WebDriverException wex) {
            Logger.fail("WebDriver Exception: ", wex);
        }
    }

I get the following error for the sendKeys() step:

org.openqa.selenium.UnsupportedCommandException: unknown command: unknown command: session/efe1d404f94de0019443b240970829d1/se/file

  • I think you want ((RemoteWebElement)THE ELEMENT OF TYPE FILE).setFileDetector(new LocalFileDetector()); Right now you're setting it on the driver. See this thread: https://stackoverflow.com/questions/65323024/while-using-selenium-grid-how-do-we-access-downloaded-file-in-node-machine-from/65323499#65323499 – pcalkins Oct 04 '22 at 20:54
  • Thank you for your reply but it didn't work. Here's what I did: `executeScript("arguments[0].style.display = 'block';", driver.findElement(by));` `WebElement uploadFile = driver.findElement(by);` `((RemoteWebElement)uploadFile).setFileDetector( new LocalFileDetector());` `uploadFile.clear();` `uploadFile.sendKeys(path);` This returned the same exception. – Zach Square Oct 05 '22 at 00:38
  • Make sure the remote end is a grid. I think only the grid would understand that command from the driver. – pcalkins Oct 05 '22 at 16:19
  • an alternative would be to upload the file to the docker image and then just send keys normally with the uploaded file's destination/path (inside docker). – pcalkins Oct 05 '22 at 17:12

0 Answers0