-5

first week coding. I am creating a programme in python to automatically upload invoices into a job management system. I am using selenium to navigate through webpages and click upload. i am prompt with the upload file box and all i want to do is type the file name and press enter.

The upload file box opens and is ready for me to type how do i do this then carry on using selenium?

code box

U13-Forward
  • 69,221
  • 14
  • 89
  • 114

2 Answers2

1

You have to find <input type="file"> and use sendkeys("/path/filename") without click() on this element. And later click button which sends it.

import selenium.webdriver

driver = selenium.webdriver.Firefox()
driver.get('http://the-internet.herokuapp.com/upload')

filename = '/full/path/to/file'

driver.find_element_by_id('file-upload').send_keys(filename)
driver.find_element_by_id('file-submit').click()
furas
  • 134,197
  • 12
  • 106
  • 148
0

As we know selenium doesn't support windows based pop up handling so use Autoit tool to write a script with desired file name.

Inject same script in your selenium test function.