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()
4
  • What error do you get? Include the traceback in your question Commented Aug 12, 2017 at 17:11
  • In custojusto.pt/ai/form/0 site we have 2 input which have image - tag name . which one you are using? Commented Aug 12, 2017 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 <module> upload() File "C:\Users\abc\workspace\ROBOT\upload.py", line 15, in upload driver.find_element_by_name('image').send_keys("images-na.ssl-images-amazon.com/images/I/…) File "C:\Python34\lib\site-packages\selenium\webdriver\remote\webelement.py", line 349, in send_keys 'value': keys_to_typing(value)}) Commented Aug 12, 2017 at 17:48
  • "Ankur Singh" I only can see one input to upload image this one: <input type="file" name="image" class="fixed" id="up" title="Clique para adicionar uma imagem"> Commented Aug 12, 2017 at 18:01

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.