-1

I have a program which uses WebDriver for going through web pages and doing some things. I faced with problem: when I need to choose file in file selection window. I know that there is an AutoIt which can do it. But there are two points:

  1. AutoIt need to be installed on the computer where you run a program
  2. Installation file doing smth wrong and you need to go to regedit and add some info in order to "complete the installation correctly" :)

And if the first point is fine (because the installer of AutoIt is common and understandable), the second point causes difficulties because users of my program won't open regedit and dig into it (even if steps to fix above-mentioned problem are simple).

So, I want to do the same, but without using another program. I only know that I can use

[DllImport("user32.dll")]
//here's should be name of the function to import

but how? Can anyone please help me to figure out how to do this task:

  1. to take control of the file selection window
  2. insert there file location
  3. press "Ok" button or just press enter

That's all I need.

Here's the example of code in which I used AutoIt:

using AutoItX3Lib;

AutoItX3 autoIt = new AutoItX3();
autoIt.WinActivate("File Upload");
Thread.Sleep(1000);
autoIt.Send(@"file's location");
Thread.Sleep(1000);
autoIt.Send("{ENTER}");
Zirochka
  • 146
  • 2
  • 10
  • Confused. Are you looking for an AutoIt solution or a Selenium solution? – Dave Becker Mar 27 '17 at 13:16
  • have you seen this? http://stackoverflow.com/questions/11256732/how-to-handle-windows-file-upload-using-selenium-webdriver – Dave Becker Mar 27 '17 at 13:18
  • I'm not looking for AutoIt solution (because there is a problem in installation). I'm looking for any solution (like work with user32.dll or maybe smth else). Thanks for a link. I have a Uploadify case, I suppose because there is no ``. – Zirochka Mar 27 '17 at 13:38
  • Possible duplicate of [How to handle windows file upload using Selenium WebDriver?](http://stackoverflow.com/questions/11256732/how-to-handle-windows-file-upload-using-selenium-webdriver) – JeffC Mar 27 '17 at 20:15
  • @Zirochka In general there no such installation hurdle for AutoIT. You don't even need to regedit if are sure about what to & how to do. Once you setup the AutoIT configuration for an element in a particular browser environment you can execute the intended file upload usecase without any modifications. Let me know if you need more help on this. – undetected Selenium Mar 27 '17 at 20:36
  • @JeffC do you see the language in my question (C#) and in question you sent (Java)? I know that in Java there is a class Robot, I know it. I asked about C#. – Zirochka Mar 27 '17 at 23:47
  • @Dev I tried on 4 different computers and just after installation I always get the same error. I found answer on stackoverflow and after doing all the steps in that answer - error left. – Zirochka Mar 27 '17 at 23:51
  • Did you look at it? It's 2 lines of code that can be easily interpreted into C#. The more important part is the concept of how it's done and that you don't need AutoIT or Robot, etc. – JeffC Mar 28 '17 at 00:11

1 Answers1

1

These steps may help you to work with AutoIT:

  1. As you are complaining about registry edit, run CCleaner once to remove all the unwanted registry entries.
  2. Download AutoIT & AutoIT Editor from this link.
  3. Install AutoIT & AutoIT Editor installer.
  4. Let Selenium open the browser and click on "Choose File" button.
  5. Prepare AutoIT script & convert it to an Application (.exe).
  6. Use the exe file in your Selenium code to get help in selecting the file.

    public class FileUploadAutoIT {
    
    public void testFileUpload() throws Exception
    {       
        System.setProperty("webdriver.chrome.driver", "C:\\Utility\\BrowserDrivers\\chromedriver.exe");
        WebDriver driver = new ChromeDriver();
        driver.get("file:///C:/Utility/Resources/fileupload.html");
        driver.findElement(By.xpath(".//*[@id='1']")).click();
        Thread.sleep(5000);
        Runtime.getRuntime().exec("C:\\Utility\\Resources\\AutoIT\\Fileupload.exe");
    
        //Continue with your regular Selenium scripts
    
    
    }
    

    }

  7. As now you are back on the webpage let Selenium perform rest of the other tasks.

Let me know if this helps you.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352