RE: [selenium-users] How to automate a file upload from OSx file upload dialog box

4,628 views
Skip to first unread message

Mark Collin

unread,
Feb 19, 2013, 4:34:47 PM2/19/13
to seleniu...@googlegroups.com

Just perform a sendKeys() on a WebElement that is an <input type=”file”>.

 

Don’t try clicking on it.

 

From: seleniu...@googlegroups.com [mailto:seleniu...@googlegroups.com] On Behalf Of Anu S
Sent: 19 February 2013 20:02
To: seleniu...@googlegroups.com
Subject: [selenium-users] How to automate a file upload from OSx file upload dialog box

 

Hi,
I need to automate a file upload from My computers in OS. Scenario as follows. 1). Select Browse button but that file name box is disabled until I select a file 2). select some directory structure and select that file. 3. Now select enabled Open button of Macs default file upload dialog box. 3. Now file appears in type=file input box. Pls HELP. Tried all,
-Anu

--
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/-/lta9QiK6-sYJ.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

ASP

unread,
Feb 19, 2013, 5:47:44 PM2/19/13
to seleniu...@googlegroups.com
you could do something like 

webDriver.findElement(By.xpath("//input[@id='fileContent']")).sendKeys("filepath");


ASP

David

unread,
Feb 20, 2013, 2:42:13 AM2/20/13
to seleniu...@googlegroups.com
Do note that since Mac OS is mentioned, if the browser is Safari, and using WebDriver, file uploads are not supported by SafariDriver.

Should be ok for other browsers as others have mentioned how to do it.

Naveen

unread,
Jun 16, 2014, 4:33:47 AM6/16/14
to seleniu...@googlegroups.com
Hi,

If it is an input field, I could use Sendkeys method. But, what if there is an UPLOAD button which prompts for MAC OS dialog box.
In Windows machine we can do this with AutoIT tool. But I didn't find any support for MAC to handle these type of dialogue boxes.

Please let me know If there is any way.

Thanks,
Naveen

Krishnan Mahadevan

unread,
Jun 16, 2014, 7:34:36 AM6/16/14
to Selenium Users

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribbings @ http://rationaleemotions.wordpress.com/


--
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.

Panikera Raj

unread,
Jun 16, 2014, 7:42:34 AM6/16/14
to seleniu...@googlegroups.com
Hi Naveen,
 
You can use Sikuli tool. Here you can find the sikuli standalone .jar fie 
 
Add to your project directory and use it.
 
 
Regards,
Panikera

 

Gadigeppa Jattennavar

unread,
Jul 9, 2014, 10:16:38 AM7/9/14
to seleniu...@googlegroups.com

When you click on ‘Choose File’ button, OS native file select dialog will be opened. This dialog will not be recognized by your driver, so when uploading any file you should never click on ‘Choose File’ button. Instead, use sendkeys to select the file,

WebElement El = driver.findElement(By.id("'fileUploadField'"));
El.sendKeys("c:\\temp\\test.txt");

This will select your file without having to select it through file select dialog. This works flawlessly across all supported drivers.

If you are running your test on grid then you should let your remote driver know that the file is residing on local machine and not remote machine. This can be achieved by setting LocalFileDetector for RemoteWebElement,

WebElement El = driver.findElement(By.id("'fileUploadField'"));
((RemoteWebElement) El ).setFileDetector(new LocalFileDetector());
El.sendKeys("c:\\temp\\test.txt");


Here you are setting local file detector for file upload element, so whenever you use sendkeys on this element, your RemoteWebDriver uses this file detector object to detect the file. If the file is detected then it will be base64 encoded and uploaded to remote server through JSON Wire Protocol and the remote fixed path will be selected as a file path.

Please check my blog http://muthutechno.wordpress.com/2014/07/09/uploading-files-in-selenium-webdriver/

Vinothkumar Velusamy

unread,
Jul 13, 2014, 4:19:49 PM7/13/14
to seleniu...@googlegroups.com
U can also try using Robot() class based on keyboard events...


--
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.

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



--
Thank you,
Vinothkumar Velusamy
1-408-685-1265

Reply all
Reply to author
Forward
0 new messages