Search code examples
pythonseleniumpywinauto

Uploading Image with requests/selenium/pywinauto


Am trying to automate some postings on a couple different websites. Basically fill out my form and upload them to 3 sites with Selenium or requests. The image upload on this site opens a new window and asks you to specify the file path, or you can drag and drop the files. Here is what is looks like. Here is what it looks like

And without CSS here is what it looks like.

enter image description here

I abandoned requests earlier thinking there was no way I was going to be able to do anything with it. Moved to selenium and can click on the button and open the window but cannot actually place an image to upload in there. I have tried pywinauto and keep getting ElementNotVisible. I am having a hard time looking through the docs to find what to actually do. Where to go from here?


Solution

  • Try the below.

    eleBrowse = WebDriverWait(driver, delay).until(EC.presence_of_element_located((By.XPATH, '//input[@type='file']'))) 
    # replace the path below with the one which you want to upload. If you want to send multiple files use comma as separator.  
    eleBrowse.send_keys("path")