JimCarter Posted July 14, 2011 Posted July 14, 2011 (edited) Well, I got my AutoIT script to work, but it only works if the executable is loaded prior to running my Selenium tests. I am utilizing AutoIT to allow my to upload files because of the IE security restrictions surrounding javascript and the file uploader. I need to be able to start AutoIT processes and shut them down in my different tests, maily because I need to specify different file paths. The following is my C# code I am using to load my compiled AutoIT script that will click the browse button, find the "Choose File to Upload" window, specify the file path and click the Open button. Again, this all works fine if I have a version of the AutoIT script exe running prior to my Sellenium tests. Otherwise the behavior is that the Browse button is clicked by my AutoIt script successfully but the "Choose File to Upload" dialog box just sits there and the file is never specified. I am assuming it can't find the window handle for some reason... 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']"); } } Edited July 14, 2011 by JimCarter
JimCarter Posted July 14, 2011 Author Posted July 14, 2011 Wow, what a pain. I found another post dealing with a security restriction workaround. I guess you can't directly click the IE fileupload control using: _IEAction($oFileUpload, "click") You need to move the mouse and do a MouseClick instead: MouseMove(_IEPropertyGet($oFileUpload, "screenx") + _IEPropertyGet($oFileUpload, "width") - 10, _ _IEPropertyGet($oFileUpload, "screeny") + _IEPropertyGet($oFileUpload, "height")/2) MouseClick("left")
PiotrK Posted October 5, 2011 Posted October 5, 2011 Hi Jim, Ca you help me with this. I've found your topic about autoit, selenium and C#. Please help me because I can't manage with this autoit script to upload the file. I would like to test, upload one file from my PC to my www page. I'veread that I can use AutoIT tool with Selenium to that. But I don'tknow how can I use this AutoIt to create script and use it.Can you help me with this, please? I'm newbie with AutoIt.For simple example:1. I'm open http://tinypic.com/2. Press button to upload the image (Browse)3. Search image file from PC and upload the image4. Press "Upload now" button on the pageAd.1I have simple selenium code to open the page:namespace SeleniumProject.Blog{ class AutoIt { private ISelenium selenium; [setUp] public void SetupTest() { selenium = new DefaultSelenium("localhost", 4444,"*firefox", "http://tinypic.com/"); selenium.Start(); selenium.WindowMaximize(); } [Test] public void AutoITtest() { selenium.Open("/"); } }Ad.2 and Ad.3I don't know here how AutoIt script should looks like Can you help me with this to prepare AutoIt script to upload thefile and connect this with my selenium code.Thanks a lot!!Piotr
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