How to upload file with splinter?

1,264 views
Skip to first unread message

Anderson Ribeiro

unread,
Sep 1, 2014, 5:39:45 PM9/1/14
to splinte...@googlegroups.com
I managed to open the window, but I can not attach the file.

from splinter import Browser

browser = Browser('firefox')
browser.visit('http://www.freepdfconvert.com/')

browser.find_by_css('div input[type="file"]').first.click()
browser.attach_file('file', 'test.docx')

I get the following error:

Traceback (most recent call last):
  File "D:/Meus documentos/python/scripts/upload/upload.py", line 10, in <module>
    browser.attach_file('file', 'test.docx')
  File "C:\Python27\lib\site-packages\splinter\driver\webdriver\__init__.py", line 229, in fill
    field = self.find_by_name(name).first
  File "C:\Python27\lib\site-packages\splinter\element_list.py", line 53, in first
    return self[0]
  File "C:\Python27\lib\site-packages\splinter\element_list.py", line 44, in __getitem__
    self.find_by, self.query))
ElementDoesNotExist: no elements could be found with name "file"

Douglas Camata

unread,
Sep 1, 2014, 11:41:26 PM9/1/14
to splinte...@googlegroups.com
Actually, `browser.attach_file(‘file’, ‘test.docx’)` will try to find an input with name ‘file’ and attach ‘test.docx’ by typing his path in the field.


Douglas Oliveira Camata
Graduando em Ciência da Computação (UENF)

Blog: http://douglascamata.net
Github: http://github.com/douglascamata
Twitter: @douglascamata
Skype: douglas_camata
-----------------------------------
Linux User #509211
-----------------------------------
Sent from Mailbox


--
You received this message because you are subscribed to the Google Groups "splinter-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to splinter-user...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Harald Nordgren

unread,
Nov 5, 2015, 3:05:17 PM11/5/15
to splinter-users
Thanks a lot Douglas!
Reply all
Reply to author
Forward
0 new messages