AutoIT and Selenium2

Works in Internet explorer ,Firefox ,AutoIT

AutoIT- Selenium2 :

AutoIT is needed along with selenium if there is need to automate dialog box, window alerts, Authentication pop.

So how do we use AutoIT with SeleniumWebdriver?
http://www.autoitscript.com/site/autoit/downloads/


Download and install the latest one.

Once you install you will notice following files in start menu [Windows7]


Use NotePad or AutoIT editior which you can download from here http://www.autoitscript.com/site/autoit-script-editor/downloads/

Paste below code in NotePad or Editor In my case Im using Editor
Change the username and password as per your need;

AutoIT_Selenium_Firefox_IE_Chrome_Authentication("Authentication Required","OK") func AutoIT_Selenium_Firefox_IE_Chrome_Authentication($winTitle,$buttonName) WinWaitActive($winTitle)if WinExists($winTitle,"") Then sleep(2000) Send("username") Send("{TAB}")    Send("password") sleep(2000) Send("{TAB}") Send("{ENTER}") sleep(2000)EndIfendfunc

Save the file as AutoITpopuphandler.au3

Now select RunScript from here 

Once you click on that Runscript it asks add .au3file 
Click ok 

Now Open the Firefox Window with authentication page like this 

Once you run the script you could notice Username and password values gets entered:


Now select CompiletoScriptexe from here


Select the .au3file where you have saved earlier for me it is C:\AutoITpopuphandler.au3
In destination file  give anything as you need but with .exe  like this C:\AutoITpopuphandler.exe

once .exe is created 
Open Eclipse:
Here only Running AutoIT with code is mentioned  
Run Below Code 

  @Test 
    private void AutoItTest() throws IOException
    {
        java.lang.Runtime.getRuntime().exec("C:/AutoITpopuphandler.exe");
    }









29 comments:

  1. extremely good... i researched a lot to find this whole information... thanks

    ReplyDelete
  2. Good one. Very informative. Keep writing

    ReplyDelete
  3. Is it possible to return data from autoit sript to webdriver selenium?
    Please Help.
    My task is : I have to click a link on Firefox so download dialog box(window popup not browser) will appear and than i have to open file(file is txt so will open in notepad). Now i have to assert that file has some particular line in it. While doing this My Selenium script should wait for the result, or may take input from autoit about that line. If that line is present script should move forward else should fail.

    I am have automated upto opening my file in notepad but problem is how to get some return value from autoit and how to wait in selenium till that value comes.

    ReplyDelete
    Replies
    1. File handling use file reader provided by java

      Delete
  4. Hi Santhosh,

    I am facing some issue with by below code, i am very new to both selenium webdriver and Autoit,kindly help me out.The issue is after opening the url the aunthecation popup appears but the Autoit is not typing the username n password that time only after the website dies or after the timeout ,the autoit handles the pop up, kindly advise me on this


    public class Autoit {

    @BeforeTest

    public void openbrowser()
    {

    WebDriver ob = new FirefoxDriver();
    Autoit ob1 = new Autoit();

    ob.get("ftp://ftp.radiogarage.com");

    ob1.AutoItTest();

    ob.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);

    }

    @Test

    private void AutoItTest() throws IOException
    {
    java.lang.Runtime.getRuntime().exec("C:\\Users\\SRI\\Desktop\\Autoitpopuphandler.exe");
    System.out.println("done success");

    }

    }


    ReplyDelete
    Replies
    1. use below code but change the content accordingly

      process_window_if_it_exists("Save As")

      func process_window_if_it_exists($winTitle,$location)
      WinWaitActive($winTitle)
      if WinExists($winTitle,"") Then
      sleep(2000)
      Send($location)
      Send("{TAB}")
      Send("{TAB}")
      Send("{TAB}")
      Send("{TAB}")
      Send("{ENTER}")
      EndIf
      endfunc

      Delete
    2. is your solved by now i couldn't see your reply in time .. let me know if you have not able to get will help you

      Delete
    3. Could you please help me with the $location parameter(also the $winTitle), meaning the argument to be passed for location? What exactly needs to be passed there, with example would be really helpful.

      Delete
    4. can anyone help me with the code for attaching the file form the windows.

      Delete
  5. Hi Santhosh..Good article
    I have one question , what if firefox asks for authentication second time even though we enter correctly for the first time?

    ReplyDelete
  6. This comment has been removed by the author.

    ReplyDelete
    Replies
    1. I have the following code
      MouseMove(1050, 310)
      MouseClick("left")
      WinActivate("Choose File to Upload")
      WinFlash("Choose File to Upload")
      Sleep(10000)
      Send("aaa.xlsx")

      Send("{Enter}")
      Sleep(10000)
      Send("{TAB}")
      Sleep(10000)
      Send("{Enter}")
      when I call it from selenium webdriver code as follows using exe
      java.lang.Runtime.getRuntime().exec("C:/Users//clickBrowse.exe");
      code does click on Browse button but file upload window does not open
      When I click on exe manually every thing is working perfectly
      I am using IE8 browser.
      please advise

      Delete
    2. For uploading files you can just use sendKeys method, pass the file path as argument

      Delete
  7. Hi Guys, I need a code which integrates autoit with webdriver for downloading pdf... can u guys help me out

    ReplyDelete
  8. will Auto It works on Linux environment ?

    ReplyDelete
  9. Hi santosh, when i click a link openwith/save as dialog pops up, i need to click openwith word, then i need to click save as in word.

    this should be done using auto it..can u please help...can u send your email..i can sedn attachement

    ReplyDelete
  10. Hi Santosh,

    I want to execute the file script file in Selenium RC , Will you please guide.

    ReplyDelete
  11. Thanks for the information - I struggled for two days with that authentication popup window until I find this topic.
    But I had errors until I changed autoIT code text to:

    AutoITAuthentication("Authentication Required","OK")
    func AutoITAuthentication($winTitle,$buttonName)
    WinWaitActive($winTitle)
    if WinExists($winTitle,"") Then
    sleep(2000)
    Send("username")
    Send("{TAB}")
    Send("password")
    sleep(2000)
    Send("{TAB}")
    Send("{ENTER}")
    sleep(2000)
    EndIf
    endfunc

    ReplyDelete
  12. How to use autoit in selenium for upload photo

    ReplyDelete
  13. Hello Santhosh, Is is possible to pass parameter to autoit from selenium..if so could you please help me on it

    ReplyDelete
  14. Hi Santhosh,
    In my application,when I click on delete link a modal dialog box opens to confirm delete with Yes or No.I've used driver.switchTo().alert().accept(); but its throwing NoAlertPresentException.I'm using selenium2 with pagefactory.
    Could you plz help me in sorting this issue?

    Thanks in-advance.

    ReplyDelete
  15. Hi Santhosh,,,


    Is it possible to do web automation using Autoit

    ReplyDelete
  16. Actually i am familiar with Autoit windows automation . I need to do web automation using autoit. Thats y i am asking it will support web

    ReplyDelete
  17. FYI, another option that's available now: https://github.com/daluu/AutoItDriverServer. See the Selenium integration demo script.

    ReplyDelete
  18. I am facing a problem while uploading file. i did not get exactly what u told above. how do i use it with selenium
    plz help me
    these are the detail of the application and the code.
    plz help me
    http://202.164.37.6:740/#
    Username-test
    pass-test
    Login in the application then u see a folder on the desktop. check link image
    http://i.imgur.com/JOdWedy.png
    Open this folder now
    http://i.imgur.com/BUScDh3.png
    When u click on this icon a pop-up open to upload documents
    i have tried this code but i am unable to upload documents
    Plz help me


    "import java.util.concurrent.TimeUnit;

    import org.openqa.selenium.chrome.ChromeDriver;


    public class document {



    public static void main(String[] args)throws InterruptedException {
    // TODO Auto-generated method stub


    System.setProperty("webdriver.chrome.driver", "D:\\chromedriver.exe");
    ChromeDriver Driver = new ChromeDriver();
    Driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
    Driver.manage().window().maximize();
    Driver.get("http://http://192.168.0.119:740//");
    Driver.findElementByXPath(".//*[@id='loginName']").sendKeys("test");
    Driver.findElementByXPath(".//*[@id='txtPwd']").sendKeys("test");
    Driver.findElementByXPath(".//*[@id='btnLogin1']").click();

    Driver.findElementByXPath("//*[@id='vis_linkScroll']/ul/li[1]/a/img").click();
    Driver.findElementByXPath("//*[@id='mainroot_1']/div[1]/div/div/ul/li[1]").click();

    }

    }
    "

    ReplyDelete
  19. I am new to Autoit. How to get the autoit function return values in selenium. can we directly assign to String like this
    String stringtext = Runtime.getRuntime().exec("D:\\AutoItScipts\\downloadWindow.exe");
    System.out.println(stringtext);??????

    ReplyDelete
  20. I am using AutoIT in Selenium Webdriver to handle Windows authentication pop up.
    It works flawlessly everytime when i run from eclipse.

    However, when i run the test as a jenkins job in my jenkins slave machine, user/pwd

    is not entered in the authentication window and my test fails.

    What is the fix for this?

    ReplyDelete