views:

114

answers:

2

I need upload file on the website. But Have a problem, i can't choose file automatic in code. Always browser show me choose file window. What wrong in my code?

IE ie = new IE("https://www.xxxx.com/WFrmlogin.aspx");
FileUploadDialogHandler uploadHandler = new FileUploadDialogHandler(@"D:\065-6405_URGENT.xls");

ie.WaitForComplete();
ie.TextField(Find.ById("txtUser")).TypeText("login");
ie.TextField(Find.ById("txtPassWord")).TypeText("***");

ie.Button(Find.ById("btnok")).Click();
ie.WaitForComplete();


ie.GoTo("https://www.orientspareparts.com/inq/WFrmUpOption.aspx");
ie.WaitForComplete();

ie.DialogWatcher.Clear();
ie.AddDialogHandler(uploadHandler);
// This code show choose file dialog
ie.FileUpload(Find.ById("FilUpload")).ClickNoWait();


ie.Button(Find.ById("butUpload")).Click();
ie.WaitForComplete();
A: 

This page may help: http://www.codeproject.com/KB/testing/WatiNConfirmDialogs.aspx

calebpburns
A: 

why do you need to select from the Dialog.. Try to just sent the Text:

ie.FileUpload(Find.ById("profile_file")).Text = "C:/Desktop/image.jpg";

I guess you might talk to the fellow who asked this Q: http://stackoverflow.com/questions/3065611/watin-file-upload/3409802#3409802

Shady M. Najib