Forum Discussion
ArtemS
Alumni
14 years agoHello,
Unlike other INPUT controls, the values of file controls (<input type="file".../>) in most browsers cannot be programmatically assigned via the Text, Value or any other properties. This is done intentionally as a security precaution.
The only possible workaround is to simulate the same actions a regular user would perform: click the Browse button, type in the file name in the ensuing Open File Dialog, click Open and then click Submit. A TestComplete script performing these actions would look similar to this:
The drawback of this approach is that the Open File Dialog depends on the browser and OS versions. Besides that, since IE8, the dialogs are created in the helper iexplore processes, whose index may change depending on the order the tested page was opened. Note the index = 2 in Sys.Process("iexplore", 2).
I hope this workaround is enough reliable for you. Artem.
Unlike other INPUT controls, the values of file controls (<input type="file".../>) in most browsers cannot be programmatically assigned via the Text, Value or any other properties. This is done intentionally as a security precaution.
The only possible workaround is to simulate the same actions a regular user would perform: click the Browse button, type in the file name in the ensuing Open File Dialog, click Open and then click Submit. A TestComplete script performing these actions would look similar to this:
function UploadTest()
{
var iexplore;
var dlgChooseFileToUpload;
var page;
iexplore = Sys.Process("iexplore", 2);
page = iexplore.ToUrl("MyPage.htm");
// Coordinate-based click over the Browse button.
page.File("extension_file_input").Click(1005, 5);
// Perform actions in the dialog
dlgChooseFileToUpload = iexplore.Window("#32770", "Choose File to Upload");
dlgChooseFileToUpload.Window("ComboBoxEx32").SetText("C:\\Users\\automation\\Desktop\\VSE 8.8\\VIRUSCAN8800.zip");
dlgChooseFileToUpload.Window("Button", "&Open").ClickButton();
// Initiate the upload
page.Button("Submit").Click();
}
The drawback of this approach is that the Open File Dialog depends on the browser and OS versions. Besides that, since IE8, the dialogs are created in the helper iexplore processes, whose index may change depending on the order the tested page was opened. Note the index = 2 in Sys.Process("iexplore", 2).
I hope this workaround is enough reliable for you. Artem.