Re: Upload file on mac OS using webdriver

2,902 views
Skip to first unread message

Brijesh Yadav

unread,
Mar 12, 2013, 2:42:25 PM3/12/13
to seleniu...@googlegroups.com
Can anyone help in this problem ?

Manoj K

unread,
Mar 13, 2013, 3:02:41 AM3/13/13
to seleniu...@googlegroups.com
Brijesh,
  
Few details, will help people to understand the problem and help

RC or Webdriver ?
browser ? version ?

What are you trying to do exactly ? 

A source code snippet of that upload button.

Regards,
Manoj

SACHIN V

unread,
Mar 13, 2013, 3:20:59 AM3/13/13
to seleniu...@googlegroups.com
Hi Brijesh,

If you want to upload document in MAC OS using Safari browser, then you can try using Apple Script to do it. For any other browser, it same as working on that particular browser on Windows platform.


--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/pU_gQNbZuSYJ.

For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
Thanks & Regards,

V Sachin

David Lai

unread,
Mar 13, 2013, 4:24:50 AM3/13/13
to seleniu...@googlegroups.com
I'm using Webdriver with Python bindings on Mac.  The send_keys() will handle everything.

If you're using Java, then you'll need to set a file locator.  Here's a good article on doing file uploads, the same wroks for local webdrivers too.

Brijesh Yadav

unread,
Mar 13, 2013, 4:51:43 AM3/13/13
to seleniu...@googlegroups.com
thanks to all for your valuable reply..

@ Manoj 
I am using
Mozilla Firefox v12
Webdriver backed selenium
Eclipse with java

I have done it on windows using autoIT and its working fine on windows but not on Mac.
---------------------------
@ Sachin
Can you provide me the sample code in apple script for uploading file on Mac using webdriver.
---------------------------
@David Lai

I will try as you suggested me to do and then i'll update 
 

Mark Collin

unread,
Mar 13, 2013, 5:44:50 AM3/13/13
to seleniu...@googlegroups.com
You can't SafariDriver doesn't support file uploads.

https://code.google.com/p/selenium/issues/detail?id=4220



On 12/03/2013 06:09, Brijesh Yadav wrote:
> How can we upload file on mac through selenium, With the windows it is
> easy to upload file but with the mac that code does not work.
> Can any one tell me how can we upload file on mac system using
> selenium or webdriver.
> --
> You received this message because you are subscribed to the Google
> Groups "Selenium Users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to selenium-user...@googlegroups.com.
> To post to this group, send email to seleniu...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/selenium-users/-/gUK6mXOR1FsJ.

Brijesh Yadav

unread,
Mar 13, 2013, 11:40:44 AM3/13/13
to seleniu...@googlegroups.com


I have tried this code with Mozilla firefox V12 (driver.findElement(By.id("cache_folder")).sendKeys("Path"));
   but it does not work, Is there any other way for uploading the file. 
    

David

unread,
Mar 13, 2013, 2:21:12 PM3/13/13
to seleniu...@googlegroups.com
The file detector that David Lai suggested shouldn't be necessary if you're doing uploads locally. It's only needed if you upload remotely to a grid node or RemoteWebDriver.

I suggest trying Chrome or different Firefox version if FF12 doesn't work.

And for uploads using external tools, if not using AppleScript, consider Sikuli, a cross platform image based solution that would work on Windows as well.

Brijesh Yadav

unread,
Mar 14, 2013, 10:59:50 PM3/14/13
to seleniu...@googlegroups.com
I am not familiar with Sikuli , i will have to give the time for understanding this tool and my problem is that i don't have so much time to go through with this tool.

Is there any way that we can upload file with the help of javascript or jquery? I investigate on this but i haven't found any clue on it. 

David Lai

unread,
Mar 15, 2013, 1:13:52 AM3/15/13
to seleniu...@googlegroups.com
It's best to use that locally too.  Ideally your tests should be able to work interchangeably with any flavor webdriver so you can run on different platforms at a moment's notice.

Manoj K

unread,
Mar 15, 2013, 10:42:10 AM3/15/13
to seleniu...@googlegroups.com
Brijesh,
   No, It cannot be done with the Js, only thing that can be suggested is the use of Sikuli and Apple Script.

Make Sikuli to click on the Upload button. (this should be fairly simple and no need for much knowledge on this tool.)
Now, the upload Finder window is opened, make use of Apple Script to locate the path(Hint: make use of Cmd+shift+G)

Hope that helps.

Regards,
Manoj

David Lai

unread,
Mar 15, 2013, 1:22:03 PM3/15/13
to seleniu...@googlegroups.com
I think there's gotta be a better way than using applescript/sikuli.  Perhaps converting the file to a DataURI then using JS to set it as a value that gets passed into the form and override the file input.

Problem with sikuli is it's image recognition based, and will severely hamper your ability to run parallel instances on the same machine once you start down that path.

David

unread,
Mar 15, 2013, 5:51:30 PM3/15/13
to seleniu...@googlegroups.com
Yes, Sikuli is not an ideal choice. AppleScript is better, but unfortunately AppleScript can be a bit tricky to learn to write.

I don't recommend JS solutions because JS is sandboxed in the browser, even with WebDriver JavascriptExecutor. Therefore, to use it, you'd have to un-sandbox JS by relaxing default security settings, which is possible but not sure if it is possible cross-platform for all browsers. And setting value for file upload is one area that is sandboxed by default.

David Lai, it would be nice to elaborate on your DataURI & JS suggestion by providing an example.

David Lai

unread,
Mar 15, 2013, 9:37:36 PM3/15/13
to seleniu...@googlegroups.com
I was thinking something along the lines of..  changing the input, forcing some attributes on that represents a base64 encoded dataURI of the file, then switching it back to a file input.  It uploaded the file, but all the headers got lost so it doesn't show up reposted on that site.  I think figuring how to take that the rest of the way is beyond my technical know how.



from selenium import webdriver

driver = webdriver.Firefox()

driver.get("http://encodable.com/uploaddemo/")


script = """

document.querySelector('input#uploadname1').setAttribute('type','text');

document.querySelector('input#uploadname1').setAttribute('value', 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAZAAAABkCAYAAACoy2Z3AAAEJGlDQ1BJQ0MgUHJvZmlsZQAAOBGFVd9v21QUPolvUqQWPyBYR4eKxa9VU1u5GxqtxgZJk6XtShal6dgqJOQ6N4mpGwfb6baqT3uBNwb8AUDZAw9IPCENBmJ72fbAtElThyqqSUh76MQPISbtBVXhu3ZiJ1PEXPX6yznfOec7517bRD1fabWaGVWIlquunc8klZOnFpSeTYrSs9RLA9Sr6U4tkcvNEi7BFffO6+EdigjL7ZHu/k72I796i9zRiSJPwG4VHX0Z+AxRzNRrtksUvwf7+Gm3BtzzHPDTNgQCqwKXfZwSeNHHJz1OIT8JjtAq6xWtCLwGPLzYZi+3YV8DGMiT4VVuG7oiZpGzrZJh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E1+hJUGK8Xj4WOrVLvchxhG9AsD8cf1NwHY/GZx8qvRPXQym12xuWggAkcOipGDWHyVrrJG6fnIeOq7J47UZmR9bCHgnUDYDz37xnucXvS7aiAC9ZRD9ZQ4JC9cIbCLAHtpD3nT34HsQcKqELiXQO4gzo3dS4jIYwIu34HEAfAaAhCYS4CGMZfnyd54B3JydokNAgcSSBtcem8l5FRXem9F54iOj8+vnxEH2EIAAhCAwJ0EeAdyZ96JGgIQgMAwARrIMEIcQAACELiTAA3kzrwTNQQgAIFhAjSQYYQ4gAAEIHAnARrInXknaghAAALDBGggwwhxAAEIQOBOAjSQO/NO1BCAAASGCfwH/HdDZ7Ug1YAAAAAASUVORK5CYII=');

"""

driver.execute_script(script)

driver.find_element_by_id("uploadbutton").click()

Brijesh Yadav

unread,
Mar 18, 2013, 12:42:28 PM3/18/13
to seleniu...@googlegroups.com
Thanks to all for giving me suggestion on my problem..

@David Lai

the code you have written here, Is that working correctly? i tried but not able to do it successfully may be i don't know how to implement that..

Is there any other scripting language  that can handle it on Mac and windows, compatibility with multiple browser also..

I was trying with the sikuli but there could be conflict if there are some same images. so i not using that.

David Lai

unread,
Mar 18, 2013, 5:05:58 PM3/18/13
to seleniu...@googlegroups.com
That code snippet is more of a proof of concept that it is possible to force/emulate a file input values using javascript.  To actually get it working to do the file upload correctly, it's beyond my technical know how.  

That code I posted will upload the file (as a dataURI base64 encoded block of data), it'll look like the file uploaded, (you'll see 5kb uploaded), however, because I wasn't able to set the file name and header information properly, where normally the file you uploaded will be displayed back to you, when using this method will break.  The file will just be lying in some temp directory somewhere where it'll be garbaged collected.

David Lai

unread,
Mar 18, 2013, 5:08:48 PM3/18/13
to seleniu...@googlegroups.com
Truthfully, I don't recommend even trying to solve this issue.  I'm sure by the time it takes to figure it out, someone out there will just fix the Safari Webdriver implementation so it'll handle file uploads the normal Webdriver way.

David

unread,
Mar 19, 2013, 2:38:44 AM3/19/13
to seleniu...@googlegroups.com
Thanks for the proof of concept @David Lai, good stuff to know whether currently useful or not.

Regarding your last comment, I would agree for all other browsers on Mac, but not for SafariDriver. Based on my previous discussions with the developers and monitoring the development history, your assumption is likely wrong or off in that it would be a LONG time before that happens. The only way file uploads will work programmatically for SafariDriver based on current design is if someone redesigns the driver internals from scratch not as a native Safari driver extension (the API Apple provides for making Safari extensions) but rather something else like a whole Mac app built from scratch (which was the original SafariDriver design but later abandoned and replaced with the current design/project).

Apple just isn't really friendly towards others in exposing internal hooks to their software. Go figure that you have more Windows GUI automation tools than for Mac.
Reply all
Reply to author
Forward
0 new messages