I'm using Sahi for Test Automation of web application. I have to write a script for sahi for uploading a file. But unfortunately I don't know the way. Can anybody please help me?
Asked
Active
Viewed 2,655 times
4 Answers
3
File upload can be a complex thing depending upon any validations you do on the upload. For a starter, you can try out the following:
Synatx:
_setFile(element, filePath [, actionURL])
eg: _setFile(_file("id"), "C:\abc\efg.jpg", "formSubmit.jsp");
If there are javascript validations on the file field, you can try this hack. Before submitting the file, change the field’s type to “text”, and then set its value. Eg.
// set the file
_setFile(_file("file"), "scripts/demo/uploadme.txt");
// Change the "type" attribute of file field
if (_isIE()){
_call(_file("file").outerHTML = _file("file").outerHTML.replace(/type=['"]?file['"]?/, "type=text"));
}else{
_call(_file("file").type = "text");
}
// Set the value into the textbox
_setValue(_textbox("file"), "scripts/demo/uploadme.txt");
This works for most of the cases. If you still get any error, you can post it here.
Thanks, Vivek

Vivek V Dwivedi
- 2,510
- 2
- 28
- 39
0
You can use the following
_setFile(_file("id"), "C:\\abc\\efg.jpg");
Not sure if you need anything more complex?

Abe Petrillo
- 2,368
- 23
- 34
-
i need more complex because the file upload is not converting to text box – vinod Feb 23 '12 at 10:59
-
1You need more detail in your question, and some example code of where things are going wrong. It's impossible to decipher what your question is – Abe Petrillo Feb 23 '12 at 11:11