2

Every time I try, I got error in instruction of the find_element, can someone try upload an image to this specific web site: https://www.custojusto.pt/ai/form/0 and let me know how I can solve this?

def upload():
    driver.get('https://www.custojusto.pt/ai/form/0')
    #time.sleep(10)
    driver.find_element_by_name('image').send_keys("https://images-na.ssl-images-amazon.com/images/I/41pzTMUV7AL._SY300_.jpg")

if __name__ == '__main__':
    upload()
eyllanesc
  • 235,170
  • 19
  • 170
  • 241
romo
  • 33
  • 5
  • What error do you get? Include the traceback in your question – Arpit Solanki Aug 12 '17 at 17:11
  • In https://www.custojusto.pt/ai/form/0 site we have 2 input which have image - tag name . which one you are using? – Ankur Singh Aug 12 '17 at 17:34
  • "Arpit Solanki" here is the error: Traceback (most recent call last): File "C:\Users\abc\workspace\ROBOT\upload.py", line 18, in upload() File "C:\Users\abc\workspace\ROBOT\upload.py", line 15, in upload driver.find_element_by_name('image').send_keys("https://images-na.ssl-images-amazon.com/images/I/41pzTMUV7AL._SY300_.jpg") File "C:\Python34\lib\site-packages\selenium\webdriver\remote\webelement.py", line 349, in send_keys 'value': keys_to_typing(value)}) – romo Aug 12 '17 at 17:48
  • "Ankur Singh" I only can see one input to upload image this one: – romo Aug 12 '17 at 18:01

1 Answers1

2

First of all you can upload images using urls i believe. You need to download them manually and then upload it. You can download the image using approach discussed on below thread

How to download image using requests

Also your upload part is in a IFrame so you need to switch to Iframe first

from selenium import webdriver

driver = webdriver.Chrome()
def upload():
    driver.get('https://www.custojusto.pt/ai/form/0')
    #time.sleep(10)

    driver.switch_to.frame("image-upload")
    driver.find_element_by_name('image').send_keys("/tmp/aws.png")

if __name__ == '__main__':
    upload()
    driver.quit()

I tested the above code and it works great for me. Note once the image is uploaded , if you need to upload another image, use driver.switch_to.frame("image-upload") again as a new frame gets created and old isn't valid anymore.

Tarun Lalwani
  • 142,312
  • 9
  • 204
  • 265
  • Thank you so much, now is working from the disk drive, as that website can get links and allowed the receipt of the link in place of the file in I thought I could also do it with selenium But in fact with the link selenium always gives error.. But in fact this understanding of frame exchange was crucial to me. – romo Aug 12 '17 at 19:52