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.
--
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/msgid/selenium-users/ffda31c2-c9ab-4444-9687-380e50c9abed%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/CANikZLkzTm4kF5td039u%2Bxc2OcE-80MF%3Drk3NAXCTmHd95YyVw%40mail.gmail.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/
--
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/msgid/selenium-users/13f55d73-a91e-466a-a222-25224fbc5b78%40googlegroups.com.