I'm trying to upload a file using Selenium by sending keys (the file path). It works, but it also opens the file picker dialog and it never gets closed. It doesn't occurs any problem though, but in headless it makes the tests to fail with the error: Failed to decode response from marionette
or Tried to run command without establishing a connection
.
How can I prevent the file picker dialog from opening? I tried this solution , but it doesn't seem to work.
You should only test what needs to be tested.
The file-picker dialog should not be automated.
Have a look at the following blog post, where he demonstrates how to upload a file without a file-picker: https://www.guru99.com/upload-download-file-selenium-webdriver.html
Edit:
You should try to set the <input>
's value
property directly with JSExecutor:
WebElement element = driver.findElement(...);
JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("arguments[0].value='C:/././hello.png';", element);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.