简体   繁体   中英

Python: actually accessible file upload in splinter?

I have a web application that lets the user upload an XML-style file and then modify it in the browser.

I am trying to test the scenario with splinter. Provided I have the correct input ( id="form-widgets-body" ):

在此处输入图片说明

...I can find it no problem, as well as use attach_file with its name:

(Pdb)     brwsr.find_by_id('form-widgets-body')
[<splinter.driver.webdriver.WebDriverElement object at 0x7f2be3a32dd0>]

brwsr.attach_file('form.widgets.body', PATH_TO_FILE)

But the problem with attach_file is that it doesn't actually make the file accessible to me. Maybe it just tells the input that something has been filled in, which is nice for other kinds of tests? (eg, you can't proceed to next screen in a financial app until you upload Document X)

I tried send_keys instead, but it didn't work as expected:

(Pdb)     brwsr.find_by_id('form-widgets-body').send_keys
*** AttributeError: 'ElementList' object has no attribute 'send_keys'
(Pdb)     brwsr.find_by_id('form-widgets-body')[0].send_keys
*** AttributeError: 'WebDriverElement' object has no attribute 'send_keys'

With that said, some questions:

  1. Would send_keys actually do what I want (ie, an accessible file upload that's just like the real thing) ? If so, what is the right way to call it?

  2. If not, what else can I do? (requiring js, maybe?)

Aha! send_keys does indeed work; I just have to access the underlying selenium driver instead of just the splinter one:

    brwsr.driver.find_element_by_id('form-widgets-body').send_keys(          
        PATH_TO_FILE)  

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM