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 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')
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.