Hamza
Hamza

Reputation: 45

Selenium upload file to a webpage

I am trying to upload files to a website, that has a drop box area to upload files, I tried element.click() and it shows windows pop up to choose file, and when I tried element.send_keys('path') it raise Message: element not interactable, how to approach this problem.

here is the website: http://shareclips.net

Thanks in advance.

Upvotes: 0

Views: 190

Answers (1)

Evara
Evara

Reputation: 75

Upload input control opens a native dialog (it is done by browser) so clicking on the control or browse button via Selenium will just pop the dialog and the test will hang.

The workaround is to set the value of the upload input via JavaScript and then submit the form.

// simulate click
webdriver.ActionChains(driver).move_to_element(element).click(element).perform()
// driver is instance of webdriver
driver.find_element_by_id("IdOfInputTypeFile").send_keys(os.getcwd()+"/video.mp4")

os.getcwd() returns the current working directory. video.mp4 is located right next to the running script in the same directory.

Upvotes: 1

Related Questions