1

I'm setting up a automatisation of a upload process of a website and I am struggeling right now with uploading a picture.

Normally you would use

uploadBtn.send_keys(Path)

, but the image would just not upload. I have also been trying to implement some Javascript, so I added an attribute "type=file"

My Python code:

uploadInput = driver.find_element_by_xpath("//a[contains(.,\"Browse\")]")#
jsSetAttributeFileInput = "arguments[0].setAttribute(\"type\",\"file\")"
driver.execute_script(jsSetAttributeFileInput, uploadInput)
uploadInput.send_keys(design["DesignPath"])

The HTML of the Website:

<a href="javascript:void(0)"> Browse </a>

I expect the result to upload my picture, but it just does not upload it. I don't get any errors, but it's just not uploading. I think it has something to do with the HTML, because it is an 'a'-tag instead of an 'input'-tag

Sem_jong
  • 41
  • 12

1 Answers1

0

Try this:

uploadInput = driver.find_element_by_xpath("//a[contains(.,\"Browse\")]")
uploadInput.send_keys(os.getcwd()+"/image.png")

and find your submit button and click it.

Where os.getcwd() returns the current working directory. image.png is located right next to the running script in the same directory

bharatk
  • 4,202
  • 5
  • 16
  • 30