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? (e.g., 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:
Would send_keys
actually do what I want (i.e., an accessible file upload that's just like the real thing) ? If so, what is the right way to call it?
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)