I know this has been talked about several times at different places
but I am not able to find an appropriate solution for this problem. I
am hoping somebody on this forum can help me with this.
I have a need to upload a file using Selenium web driver preferably
but if needed can use Selenium RC. The two options availble right now
are
- Use AutoIt tool to create a script to upload a particular file. The
AutoIt script can be created using the following:
WinWaitActive("Choose file")
Send("C:\attach\samplefile.txt") \\location of the file you want to
attach to the form and submit
Send("{ENTER}")
then use the following code to call this.
package com.company;
import java.io.IOException;
import com.thoughtworks.selenium.Selenium;
public class AddAttachment {
public static void attach(Selenium selenium, String fileName) {
try {
String[] commands = new String[]{};
commands = new String[]{"c:\\test\\attachFile.exe"}; //
location of the autoit executable
Runtime.getRuntime().exec(commands);
} catch (IOException e) {}
//autoit executable is now waiting for a "Choose file" dialog
to popup
selenium.click("name=browseButton");
//once the "Choose file" dialog is opened, the autoit will
input the path and file name
}
}
but this option restrict me to upload only one file at a time which is
not what i want to do. I got to be able to upload different files
using a user configurable element
- Using user-extensions.js in the selenium RC. I have not been able to
find appropriate information on this in order to be able to try this.
Can somebody help me with this with guidance on setting up the project
and with getting the appropriate user extention for this?
Any other suggesstions will be greatly appreciated.
Thanks
Manoj
Manoj
--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/selenium-users?hl=en.
On Dec 8, 6:57 am, Simon Stewart <simon.m.stew...@gmail.com> wrote:
> In WebDriver, just use "WebElement.sendKeys" using the file name as the
> argument to the file input element.
>
> Regards,
>
> Simon
>
> >http://groups.google.com/group/selenium-users?hl=en.- Hide quoted text -
>
> - Show quoted text -
==============
AutoItSetOption("WinTitleMatchMode","2") ; set the select mode to
select using substring
;Normally run from command line
if($cmdLine[0] > 2) then
$titlex = $cmdLine[1] ;Title of the window
$form = $cmdLine[2] ;Name of the file upload/save form object
$file = $cmdLine[3] ;Path of the file to upload
Else
;Testing fields
$titlex = "Files"
$form = "ctl00$ContentPlaceHolder1$FilesView$ctl02$NewFile"
$file = "C:\\Users\filename.txt"
EndIf
WinWait($titlex) ; match the window with substring
$title = WinGetTitle($titlex) ; retrives whole window title
WinSetState($title, "", @SW_MAXIMIZE) ;Maximize the window incase
button is hidden
WinActivate($title)
WinWaitActive($title)
$oIE = _IEAttach ("Files")
$oT = _IEGetObjByName ($oIE, $form)
;Move the mouse to the button on the form and click it
MouseMove (_IEPropertyGet ($oT, "screenx") + _IEPropertyGet ($oT,
"width") - 10, _IEPropertyGet ($oT, "screeny") + _IEPropertyGet ($oT,
"height") / 2)
MouseClick ("left")
;Wait for upload screen then input the file and close it
WinWait ("Choose File to Upload")
$hChoose = WinGetHandle ("Choose File to Upload")
ControlSetText ($hChoose, "", "Edit1", $file)
ControlClick ($hChoose, "", "Button2")
;Restore window state
WinSetState($title, "", @SW_RESTORE)
==============
And then when calling the autoit exe file, you could pass the file
name as a parameter.
If no file name is passed, a default file will be used which is
defined in the autoit script as ""C:\\Users\filename.txt""
Also some info on the upload a resume.
As far as I know, the sendkeys function will work in browser mode
"*chrome" or basically only on firefox.
When anyother browser is used to test IE or chrome, the sendkeys
function will not work.
let me know if this was helpful.
--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/TO26QPgPgOAJ.
To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/selenium-users?hl=en-US.