1
Vote

Unable to use WaitUntil.DialogAppears("File Upload")); from webinator

description

I use the sample code that is provided in the documentaion
 
// File dialogs:
var fileUpload = LocateBy.Attributes(ByAttribute.Name("FileUpload1"));
web.Click(fileUpload, WaitUntil.DialogAppears("File Upload"));
web.Dialog.SelectFiles(Comparison.Contains, "File Upload", @"F:\images", "testUploadImage1.jpg",);
 
 
Can you please let me know if i am missing anything here
 
It throw an except {"Condition failed."}
 
Error Stack Trace says ---
 
at Webinator.Impls.ConditionInvoker.ExecuteConditionalAction(Action action, ICondition condition, ConditionType overrideConditionType) in E:\Source\Webinator\Webinator\Webinator\Impls\ConditionInvoker.cs:line 83
at Webinator.Impls.WebManager.SafeClick(Locator locator, Boolean expectAlert, ICondition condition) in E:\Source\Webinator\Webinator\Webinator\Impls\WebManager.cs:line 724
at Webinator.Impls.WebManager.Click(Locator locator, ICondition condition) in E:\Source\Webinator\Webinator\Webinator\Impls\WebManager.cs:line 217
at Webinator_UITest.Form1.button3_Click(Object sender, EventArgs e) in F:\AbhijeetPatil\PersonalData\MyProjects\Webinator-UITest\Webinator-UITest\Form1.cs:line 62
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at Webinator_UITest.Program.Main() in F:\AbhijeetPatil\PersonalData\MyProjects\Webinator-UITest\Webinator-UITest\Program.cs:line 18
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()

comments

anderslyman wrote Sep 18, 2012 at 2:59 PM

Your syntax looks good, the only thing I can think of is maybe the title of the file dialog isn't "File Upload" - that can change from browser to browser.

I think WebDriver now supports file selection dialogs (unless you want to select multiple files) so maybe it's time for me (or someone) to pass through to that functionality instead of hooking into the Windows Automation API as a workaround...

abhijeetpatil wrote Sep 18, 2012 at 3:13 PM

More info I am using only IE

i did try by changing the dialog box name it was "Choose File to Upload" but did not work.

Just FYI, I have to select only one file

Can you help me by providing some code sinpet for "WebDriver with file selection dialogs"

anderslyman wrote Sep 18, 2012 at 3:27 PM

I think it's as simple as:
IWebElement element = driver.FindElement(By.Id("uploadhere"));
element.SendKeys("C:\Some_Folder\MyFile.txt");

from here:
http://stackoverflow.com/questions/8851051/selenium-webdriver-and-browsers-select-file-dialog

In other words, you don't click the button because that will invoke the file dialog which is the domain of the OS not the browser, which precludes the usage of WebDriver - but if you instead just set the value of the file input, you can skip the dialog and set the file path directly.

abhijeetpatil wrote Sep 18, 2012 at 3:44 PM

Thanks a lot for code.
I badly stuck with implmetaion.

But for the input type=file, we cant set the value (security reason this readonly)
isn't this correct

anderslyman wrote Sep 18, 2012 at 3:49 PM

You may want to try the WebDriver user group: groups.google.com/group/webdriver

It may also be worth considering doing a POST to send the file to the server instead of controlling the browser to do the same thing - it would be a much faster and much less error-prone.

wrote Feb 14, 2013 at 1:54 AM