0

Code: <input type="file" accept="image/png, image/jpeg" style="display: none;">

What I am trying to do:

upload = driver.find_elements_by_xpath("//input[@type = 'file']") upload.send_keys('/Users/username/Desktop/images/filename.jpg')

PS : This code is not in any iframe and element can be found (I checked its attribute to be sure)

Nothing happens, I have written the same logic to upload files in other test cases and it worked.

Thanks for your help!

  • I think you'd need to submit this form for anything to happen. Show the full markup of the form and any associated scripts. – pcalkins Oct 18 '19 at 23:24
  • The `INPUT` is formatted with `display: none` which means it's not visible so can't be interacted with using Selenium by design. – JeffC Oct 18 '19 at 23:47
  • Thanks @JeffC How do I proceed in this case? Any idea? Thanks for the help :) – Deepali Agarwal Oct 21 '19 at 22:08
  • It really depends on the page so it's hard to say without seeing it for myself. It could be that you have to do something to the page to have the `INPUT` become visible. It could be that this is one of many `INPUT`s on the page and another one is visible. You probably need to do some investigation to ensure you have the right one. If it IS the right one and is invisible (and stays that way), you will need to take another approach like using JS to set the path on the `INPUT`. See [this](https://stackoverflow.com/q/47515232/2386774) as an example. – JeffC Oct 22 '19 at 01:50
  • Thanks so much for your help and guidance @JeffC. Appreciate it. – Deepali Agarwal Oct 22 '19 at 17:00

1 Answers1

0

I was able to figure out the issue. Below the input field accepts "jpeg and png" and I was trying to upload "jpg". Once I changed the input to "jpeg or png" it worked.

Code:

<input type="file" accept="image/png, image/jpeg" style="display: none;">

What I was doing :

upload.send_keys('/Users/username/Desktop/images/filename.jpg')

Solution : Change the file extension to jpeg or png.

upload.send_keys('/Users/username/Desktop/images/filename.jpeg')