JimCarter Posted July 14, 2011 Posted July 14, 2011 (edited) I have read all of the posts already on this topic but I cannot interact with the "Choose File to Upload" dialog that is used when uploading files with IE8. Basically the problem comes down to the fact that I cannot seem to get a handle to the "Choose File to Upload" window. I am running Selenium and executing a compiled version of my script. If I write a simple script that just waits for the "Choose File Upload" window and manually make the window show, I can enter the data into the File textbox with no problem. $hWnd = WinWait("Choose File to Upload") MsgBox(0,"window handle",$hWnd) If $hWnd Then ControlSetText($hWnd,"","Edit1","Test") ControlClick($hWnd, "", "Button2") EndIf here is my code that has a problem: #include <IE.au3> If $CmdLine[0] Then ; Internet Explorer is partly integrated in shell.application $oShell = ObjCreate("shell.application") ; Get the Windows Shell Object $oShellWindows=$oShell.windows ; Get the collection of open shell Windows $MyIExplorer="" for $Window in $oShellWindows ; loop through all existing shell windows if StringInStr($window.LocationURL,"ImportProcessPopup") then $MyIExplorer=$Window exitloop endif next ; find the Browse Button and Click it $oFileUpload = _IEGetObjByName ($MyIExplorer, "iFile") ;need iFile to be a param _IEAction($oFileUpload, "click") ; wait for File Upload dialog to open $hWnd = WinGetHandle("Choose File to Upload") ; if File Upload dialog opens send the file name and click enter If $hWnd Then ControlSetText($hWnd,"","Edit1",$CmdLine[1]) ControlClick($hWnd, "", "Button2") EndIf EndIf Edited July 14, 2011 by JimCarter
JohnOne Posted July 14, 2011 Posted July 14, 2011 Quote ; wait for File Upload dialog to open$hWnd = WinGetHandle("Choose File to Upload")Where exactly are you waiting here? AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans.
JimCarter Posted July 14, 2011 Author Posted July 14, 2011 On 7/14/2011 at 9:16 PM, 'JohnOne said: Where exactly are you waiting here?It's not material. I get the same behavior when I use WinWait.
JohnOne Posted July 14, 2011 Posted July 14, 2011 I see. Any chance you could post some runable code? and does it need to be compiled. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans.
JimCarter Posted July 14, 2011 Author Posted July 14, 2011 On 7/14/2011 at 9:26 PM, 'JimCarter said: It's not material. I get the same behavior when I use WinWait.OK, I it was material. Changing too many things at one time. It is working now - thanks
JohnOne Posted July 14, 2011 Posted July 14, 2011 Great AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans.
JimCarter Posted July 14, 2011 Author Posted July 14, 2011 I spoke too fast. It seems that my compiled AutoIT script only works if it is running prior to running my sellenium tests in C#. Does anyone have any experience with the combo of Sellenium, C# and AutoIT? The main two methods are shown below. public static void SelectImportToProcess(Import import) { if (import == null) throw new ArgumentNullException("import"); //find the process link and click on it and wait for popup string importXPath = "//a[contains(@href, \"ImportID=" + import.Id.ToString(CultureInfo.CurrentCulture.NumberFormat) + "\")]"; ClickAndWaitForPopup(importXPath,"Import Process Popup"); } public static void UploadFile(string filePath, string fileTextBoxLocator) { //uses AutoIt to handle communication with the Choose File To Upload dialog var procStartInfo = new System.Diagnostics.ProcessStartInfo(@"C:\Grow\Utilities\Grow.Selenium\SharedBinaries\BrowseButton.exe", filePath); var proc = new System.Diagnostics.Process {StartInfo = procStartInfo}; proc.Start(); proc.WaitForExit(5000); proc.Kill(); if (proc.HasExited) { ClickAndWait("//input[@id='btnUpload']"); ClickAndWait("//input[@value='Save']"); } }
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now