How to upload files with selenium on a Linux machine without using the sendKeys method?
Note: There is no input field for using the sendKeys method.
Below is the locator of the input field to upload a file.
Asked
Active
Viewed 476 times
0

arpita biswas
- 144
- 1
- 6
-
2Depends on how the site is doing file uploads. – Dave Newton Apr 29 '21 at 12:40
-
1Via API if it's available. You won't need Selenium for it. – vitaliis Apr 29 '21 at 12:44
-
I want to automate the file upload section of the site using selenium for testing purpose – arpita biswas Apr 29 '21 at 12:55
-
May be it is best you can add more details about the Website like page source etc. Sometimes the input field to upload a file is hidden. If so, you can enable it using JS. – Ayaz Apr 29 '21 at 12:59
-
What's about Robot? Have you tried? – Prophet Apr 29 '21 at 13:01
-
@Prophet: Yes tried from local. My question is if I want to run it from Jenkins have to give the relative path of the file like - System.getProperty("user.dir"). Is it possible? – arpita biswas Apr 29 '21 at 14:15
-
@Ayaz: I have added the required image of the locator of the input field to upload the file. – arpita biswas Apr 29 '21 at 14:16
-
1Your local machine is Windows, right? I am not sure Robot will run on Linux that's why I asked. And I also know that Robot doesn't work on Windows in headless mode. So it's a problem... – Prophet Apr 29 '21 at 14:18
-
WAIT! You have and input element there! Send the file path to it! – Prophet Apr 29 '21 at 14:19
-
Actually, there is no input field to send the file path using the sendKeys method. Only a button is available to select the file from a window. – arpita biswas Apr 29 '21 at 14:37
-
No local machine is also Linux (ubuntu). OK in headless mode it will not work. Thanks for this info. Then I think it will not work on the Jenkin server with a Linux machine right when run on headless mode? – arpita biswas Apr 29 '21 at 14:50
-
I can see the input with type="file" and id as `search-by-img-face_image` ... Is it not the same input field you want to send the keys to? – DesertPride Apr 30 '21 at 07:09
-
@DesertPride: Yes it is the same input. I cannot use the sendKeys method as there is no text field in the frontend to send the file path. – arpita biswas Apr 30 '21 at 07:22
-
1It is possible to make the invisible input field visible through javascript executor just before sending the keys. Then again make it to "display : none;" as it was before ... here are the steps : 1. change the visibility of input field to visible 2. send keys 3. change the visibility back to false. try the solution given here : https://stackoverflow.com/questions/12363038/selenium-webdriver-click-on-hidden-elements/12364198#:~:text=arguments%5B0%5D.-,style.,of%20your%20file%20input%20control. – DesertPride Apr 30 '21 at 09:02
-
@DesertPride: Thanks a lot for your help!! It is working now :) . As per your comment I enabled the hidden text field with javascript executor and able to send the file path with sendKeys method. – arpita biswas Apr 30 '21 at 11:03