Wednesday, 20 January 2016

Robot Framework and Selenium - Uploading a File

So I'm sitting here trying to upload a file using a browser's native modal Upload File dialog box, which differs greatly between operating systems -- I'm forever unsure why Apple insist that users should be shielded away from file paths and such -- and it's not working.

Problem

I am clicking on 'Upload file' in a web application, this results in a modal 'Please Choose a File to Upload' type prompt.

At this point I'm stuck. I cannot seem to identify the modal dialog box to perform the upload.

Solution

Let's try a built in Robot Framework keyword...
Choose File
which takes two parameters. An environment and a file path/file. 

I had a guess at a couple of xpaths to the dialog
//input[@type='file'] 
seems to be sufficient.

Next the file path.

I seem to be getting an error logged as INFO,
INFO File ''C:/cat_in_hat.jpg'' does not exist on the local file system
...okay. I'm pretty sure it does. So, how to resolve.
Documentation:
The file specified with `file_path` must be available on the same host where the Selenium Server is running
On Windows I simply have my filename kinda like ${filename}=    Set Variable
    ...    C:\\Users\\Documents\\random.csv
And it all works a-okay.

No comments:

Post a Comment

Robot Framework, Basic Setup

Plug: Robot Framework is quick to setup, easy to write tests for, and super fast to triage failures in. The last point really sets it apart...