0

The method is worked fine when I run tests locally, but when tests are run with a Selenium grid or Zalenium the multiple upload method not works.

String path = "a.jpg";
String path1 = "b.jpg";
String path2 = "c.jpg";

element.sendKeys(path + "\n " + path1 + "\n " + path2);

Did anyone solve this issue?

Norayr Sargsyan
  • 1,737
  • 1
  • 12
  • 26
  • What symptoms or exception of 'method not works' are you experiencing? – pburgr Dec 18 '20 at 13:47
  • org.openqa.selenium.InvalidArgumentException: invalid argument: File not found : – Norayr Sargsyan Dec 18 '20 at 13:53
  • please add the screen shot of the element when you manually upload multiple files – PDHide Dec 18 '20 at 13:56
  • after manually uploading the files the input field is disappearing, so there is nothing to take a screenshot of, what exactly do you need? – Norayr Sargsyan Dec 18 '20 at 14:07
  • @Norayr Sargsyan this should be quite easy to solve. Just debug your code to determine what file is not found. – pburgr Dec 18 '20 at 14:25
  • The first element is not found, after the "\n", The RemoteWebDriver can not understand the "\n" as a changing to the new line – Norayr Sargsyan Dec 18 '20 at 14:27
  • You need localFileDetector. See this post: https://stackoverflow.com/questions/62595459/how-to-upload-a-file-by-transfering-the-file-from-the-local-machine-to-the-remot – pcalkins Dec 18 '20 at 18:59
  • Added, the single file upload works fine – Norayr Sargsyan Dec 18 '20 at 19:25
  • looks like the getLocalFile method returns a single File: https://github.com/SeleniumHQ/selenium/blob/trunk/java/client/src/org/openqa/selenium/remote/LocalFileDetector.java That would be an issue... not sure how to get the uploaded file's path... but maybe try getLocalFile() to see if it returns remote-end path for you after using send keys? (element.getLocalFile()? and getAbsolutePath() ) If so, you could use sendKeys three different times... collect the paths, clear the field and then send keys without fileDetector. – pcalkins Dec 21 '20 at 20:55

1 Answers1

0

For handling files in remote driver you need to set FileDetector. Below is the code to set the file Detector.

RemoteWebDriver remoteWebDriver = new RemoteWebDriver(new URL(hubUrl), getDesiredCapabilties(Browser.REMOTE_WEBDRIVER));
remoteWebDriver.setFileDetector(new LocalFileDetector());
Suraj Rao
  • 29,388
  • 11
  • 94
  • 103