Skip to content
This repository has been archived by the owner on Nov 29, 2018. It is now read-only.

The SafariDriver does not support file uploads #4220

Closed
lukeis opened this issue Mar 3, 2016 · 17 comments
Closed

The SafariDriver does not support file uploads #4220

lukeis opened this issue Mar 3, 2016 · 17 comments

Comments

@lukeis
Copy link
Member

lukeis commented Mar 3, 2016

Originally reported on Google Code with ID 4220

The SafariDriver is implemented in JS and does not have the privileges necessary to
manipulate a <input type="file"> element.  Therefore, the SafariDriver does not support
file uploads.

Reported by jmleyba on 2012-07-09 21:03:28

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

Would be interesting for someone to post what the actual behavior is when someone attempts
a file upload with SafariDriver. When done across Grid2/RemoteWebDriver, assume may
encounter issue of issue 4203 or not. I would post this when I get to it.

Reported by mangaroo on 2012-07-09 22:04:13

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

I think you're confusing two separate features.  When transferring a file to the test
machine, you are using the standard HTTP client and are not bound by issue 4203.  That
has _nothing_ to do with the SafariDriver.

The issue documented here is that you cannot set the value of an <input type="file">
element (the path of the file that should be uploaded by the browser).  The behavior
is currently undefined.  The SafariDriver will probably generate a series of key events
on the element with no discernable effect.  We should probably generate an error when
the target is a file element.

Reported by jmleyba on 2012-07-10 02:27:34

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

Thanks, that's just what I wanted to know.

Reported by mangaroo on 2012-07-10 05:18:20

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

Issue 4578 has been merged into this issue.

Reported by jmleyba on 2012-09-21 03:20:15

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

I guess workaround for those that really want to do file upload for SafariDriver would
be not to do it natively via SafariDriver but by using external code libraries to perform
the upload via HTTP/HTTPS (POST) requests (combining any other form data in addition
to the file being uploaded/sent), then get response and check whether upload succeeded
or not, then go back to SafariDriver code and navigate to next page to check upload
succeeded or not, and/or to continue from there for the next steps in the automation.

This approach would be similar to the file download method using HTTP requests externally
that has been mentioned in various posts in WebDriver and Selenium user Google groups.
Here, it's just the inverse, doing upload instead of download.

Though if the upload requires a session (cookie), then you can extract Selenium session
cookie and use with HTTP request. Or if session is stored with session ID in URL, extract
that and pass along with HTTP request.

Reported by mangaroo on 2012-09-21 05:11:08

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

Thanks guys for your input. From the thread I understand the safaridriver won't support
the file upload through <input type="file"> . Can you please suggest any alternative
HTTP/HTTPS method to upload the file through Safari.


Reported by progmat82 on 2012-09-24 05:12:15

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

I believe I already stated the alternative method (i.e. workaround) in my previous comment
#5. If you need more details, refer to this blog post:

http://ardesco.lazerycode.com/index.php/2012/07/how-to-download-files-with-selenium-and-why-you-shouldnt/

The difference of that post and this issue is that now, instead of a download you're
doing an upload (typically via an HTTP/HTTPS POST request sending the file as the POST
body). The unfortunate part is that I believe nobody has built an upload library to
do this, because most of the other browsers support the file upload feature of WebDriver.
So you're on your own for building the needed library if you really need file upload
on Safari.

The easy option is to skip the file upload test on Safari and run it on other browsers,
if you can.

Reported by mangaroo on 2012-09-24 17:12:58

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

Wondering whether Safari Driver supports file upload right now ?

If support is still not available, please suggest some alternatives.

I am running a Selenium Application and would like to upload a file. I tried out following
and it didn't work.

driver.findElement(By.id("elementId")).sendKeys(file.getAbsolutePath());

Reported by dande.anupama on 2013-09-17 00:15:51

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

For comment #8, answer is no, and alternative was mentioned in comment #7, but no one
has implemented a ready to use code solution for it.

Another alternative is to do the file upload portion using AutoIt or Sikuli, etc. to
click the file uploader button and pick the file to upload rather than do it all from
SafariDriver which not support right now.

Reported by mangaroo on 2013-09-17 20:09:25

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

Issue 6344 has been merged into this issue.

Reported by jmleyba on 2013-09-30 18:13:39

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

All, what's the last decision for this issue. Are you going to fix it in the following
release or not? If no, how can we workaround bu the UI action, as in my side we are
not able to do it simply by handling request/response mentioned above.


Kindly reply if you have the idea, thanks in advance!



Reported by shenxieyin on 2013-10-14 02:20:34

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

Hello, anyone can reply the question? Thanks!

Reported by shenxieyin on 2013-10-15 06:33:39

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

Shen, if you see the resolution status, you get the answer, which means can't fix.

I'm curious as to why you say can't do this by (HTTP) request/response. A file upload
is simply an HTTP POST request with file in the multipart form data content body sent
as base64 encoded text (regardless if it is text or binary file). To workaround, mimic
what Safari would normally do, you just make the same HTTP POST from an HTTP client
(library) code and if that request requires additional data like cookies, you can extract
from Selenium and pass to the HTTP client to impersonate the session. Same with URL
query strings. The only thing you likely can't pull off selenium is any HTTP response
headers that you then need to pass back as HTTP request headers (excluding the cookie).
You can generally pull the upload location off the HTML/javascript source on the page.

Unlike similar workaround for alert handling, this scenario should work for most people.
The tricky part is no one has offered a ready made solution to do the upload via HTTP
client so you have to write your own in your preferred language.

Reported by mangaroo on 2013-10-15 17:52:41

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

The reason the proposed workaround will not work for my application is because I'm not
uploading the file. I'm just reading it in oder to display it in the browser.

http://www.html5rocks.com/en/tutorials/file/dndfiles/

Reported by nelsonwd@maverixbio.com on 2014-01-16 23:38:56

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

Hi,
is there any status update for this issue? Using safari driver 2.43 and still can't
upload file!

Reported by tanummca2003 on 2015-02-16 20:56:12

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

I am also facing this issue.Not able to upload a file using Safari web driver.Is this
a bug in selenium web driver for Safari.Can anyone please reply to my question.

Reported by kabutotester31 on 2015-03-10 10:19:59

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

Reported by luke.semerau on 2015-09-17 18:15:46

  • Labels added: Restrict-AddIssueComment-Commit

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant