Handling Windows Dialogs Using Selenium

Hi There,

Finally here comes a project built using Java along with Native Code that can handle Windows Dialogs.

The following can be automated  using Selenium - Java, on major browsers like Internet Explorer, Firefox, Chrome.
  • Downloading Files
  • Uploading Files
  • Windows Authentications
  • Error Recovery scenarios
Note: Works only in Windows Environment. cannot be used with Linux or Mac OS.

This Post is organized into following parts:

Go To: Handling Windows Dialogs Using Selenium Part 1  - Contains Details regarding Registering the DLL
Go To: Handling Windows Dialogs Using Selenium Part 2  - Contains Details regarding The usage along with Examples
Go To: Handling Windows Dialogs Using Selenium Part 3  - Contains Details regarding Upcoming Releases and Features
Go To: Handling Windows Dialogs Using Selenium Part 4  - Contains Details regarding API Methods


Current Version: 3.0

Download ATU Selenium Utilities - Windows Handler (included from version2 onwards)
Download JACOB
Download UISpy


LinkedIn Group:

you can join our LinkedIn group here for more collaborative discussions: ATU LinkedIn Group

Give our tools a Feedback:

 We are constantly working on several projects, we would like to have a feedback on all the tools so that we can prioritize, introduce new features, enhancing them etc. This will also help us in understanding the usage of these tools and lift us to develop further more utilities.

 Feedback page : ATU Utilities User Feedback


We love Automation; we love to keep its utilities Open Source. 
                                                                                                – Automation Testing Utilities

81 comments:

  1. Thank you so much for the help.Yes, I have started working on webDriver as someone has suggested the same as you did.

    ReplyDelete
    Replies
    1. You have provided really required information.
      And I have done a search for almost long time and found the below site as well along with your.

      The below website has also provided a framework structure, folder representation and steps to follow to design and implement a framework

      http://seleniumeasy.com

      Delete
  2. Hi All,

    I am getting the below exception:[ATU Windows Handler Framework Exception] Please Register the ATU_WindowsHandler.dll with your system. Refer to http://automationtestingutilities.blogspot.in/ for instructions
    at atu.utils.windows.handler.WindowHandler.(WindowHandler.java:25)
    at WinHandle.testRUN(WinHandle.java:9)
    at WinHandle.main(WinHandle.java:21)


    Frome where i can get the ATU_WindowHandle.dll file

    Regards,
    Panikera

    ReplyDelete
    Replies
    1. Hi Panikera,

      I have added the download links for the dll at the bottom of page. After downloading register the dll as explained in the post. Make sure that you have .NET v4 Installed for registering the dll.

      Regards
      Automation Tester

      Delete
  3. Hi Automation team,

    I copied the ATU_WindowHandle.dll in local directory and i run the below command
    E:\>C:\Windows\Microsoft.NET\Framework\v4.0.30319\regasm.exe ATU_WindowsHandler
    dll /codebase
    And i am getting below exception: Microsoft (R) .NET Framework Assembly Registration Utility 4.0.30319.1
    Copyright (C) Microsoft Corporation 1998-2004. All rights reserved.

    RegAsm : error RA0000 : Could not load file or assembly 'file:///E:\ATU_Windows
    andler.dll' or one of its dependencies. Operation is not supported. (Exception
    rom HRESULT: 0x80131515)

    sujjest me on this

    Regards,
    Panikera

    ReplyDelete
    Replies
    1. Hi Panikera,

      Can you recheck the command you are using to register. As per the error, it appears that the regasm utility is unable to locate the dll in E drive. Consider changing the cmg dir. Or just let me know in which drive the dll is present I would give you cmd accordingly.

      Delete
    2. Hi Automation Tester,

      I actually only have one drive so I put the ATU_WindowsHandler.dll into the C drive. I run CMD and change my Directory to C and then and this command:

      C:\Windows\Microsoft.NET\Framework\v4.0.30319\regasm ATU_WindowsHandler.dll /codebase

      I am getting RegAsm: error RA0000: unable to locate input assembly 'ATU_WindowsHandler.dll/codebase' or one of its dependencies.

      Delete
    3. Hi Mediha Aziz,

      Just a small modification for your command.

      C:\Windows\Microsoft.NET\Framework\v4.0.30319\regasm C:\ATU_WindowsHandler.dll /codebase

      This should register the DLL.

      Regards
      AT

      Delete
    4. Hi,

      I have tried like above but still getting the same error.
      RegAsm : error RA0000 : Unable to locate input assembly 'C:/ATU_WindowsHandler.d
      ll/codebase' or one of its dependencies.

      Delete
    5. Hi,

      Please go through the part 1 for registering the dll. Kindly follow the complete post to resolve the issue.

      Regards
      AT

      Delete
  4. Hi Automation Tester,
    I am experiencing small problem with jacod.dll . I have tried setting both jacob-1.17-x64.dll & jacob-1.17-x86.dll into the windows environment variables but i am getting this error message
    "Exception in thread "main" [ATU Windows Handler Framework Exception] Please add the jacob-(version-bit-type).dll file to the System path
    at atu.utils.windows.handler.WindowHandler.(WindowHandler.java:22)
    at test.main(test.java:12)" .

    I am using windows 64 bit with java 1.6 32bit ,using Eclipse Kepler and i have ATU_WindowsHandler.dll successfully registered. Any advice would be appreciated.

    Regards,
    Mike

    ReplyDelete
    Replies
    1. Hi Mike,

      Could you try placing the jacob dll in the root directory of your eclipse project. This is how I have been working out so far or alternative is to set in env, since you are facing issues also you can try loading the library using System class.

      Delete
    2. You could also try the following..

      Place the jacob-(version-bit-type).dll file in your project Root Directory.
      or
      Place it in any directory and use the below code to load the DLL file.

      System.setProperty("jacob.dll.path", "D:\\jacob-1.17-M2-x86.dll");
      LibraryLoader.loadJacobLibrary();

      Regards
      AT

      Delete
    3. It worked for me...

      I am using 64bit windows 7 with java 1.7

      Few points I noticed

      1. Need to start "cmd" as Administrator
      2. Use "C:\Windows\Microsoft.NET\Framework64\v4.0.30319\regasm.exe ATU_WindowsHandler.dll"
      Notice that the path should have "Framework64" for 64 bit .Net reference where as "Framework" for 32 bit.
      3. Should use "jacob-1.17-x64.dll" for 64bit
      4. Add "jacob,jar" as well as "ATU_Selenium_Utilities_2.0.jar" to buildpath
      Rest of the steps are as instructed by the "Automation Tester" above


      @Automation Tester : Thanks for sharing such ideas

      Delete
  5. Hi ,

    Can you please tell me how to write code for fileupload in c#.I am unable to find WindowElement in c#.Please help me

    ReplyDelete
  6. Hi Nagarjuna,

    for Selenium C#, do the following.

    Download the DLL file from the Given link in the post
    Add the DLL to your project reference
    Use the Class named "WindowsHandler" that has all the required methods
    Namespace is "ATUFramework"

    Example code in C#:


    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using ATUFramework;
    using System.Windows.Automation;
    namespace SampleConsoleApp
    {
    public class Program
    {
    static void Main(string[] args)
    {
    WindowsHandler handler = new WindowsHandler();
    AutomationElement chromeElement = handler.FindWindowByName("Apache Tomcat/7.0.42 - Google Chrome");
    AutomationElement saveAsElement = handler.GetElementByName(chromeElement, "Authentication Required");
    //further code goes...
    }
    }
    }



    Regards
    Automation Tester

    ReplyDelete
  7. Hi,

    I am getting below error.

    Exception in thread "main" java.lang.NoSuchFieldError: m_pDispatch
    at com.jacob.com.Dispatch.createInstanceNative(Native Method)
    at com.jacob.com.Dispatch.(Dispatch.java:99)
    at com.jacob.activeX.ActiveXComponent.(ActiveXComponent.java:58)
    at atu.utils.windows.handler.WindowHandlerWrapper.(WindowHandlerWrapper.java:19)
    at atu.utils.windows.handler.WindowHandler.(WindowHandler.java:20)
    at test.windowshandler.WindowsHandlerTest.testRUN(WindowsHandlerTest.java:126)
    at test.windowshandler.WindowsHandlerTest.main(WindowsHandlerTest.java:48)


    Mine is windows7(64bit) machine.
    Could you please help me.

    ReplyDelete
  8. Hi Syam,

    are you using Jacob 32 bit or 64 bit dll file for your project ?

    ReplyDelete
  9. Replies
    1. Hi,

      while registering the dll.. Have you used the RegAsm.exe from 64bit folder of the .Net Framework? as shown below

      C:\Windows\Microsoft.NET\Framework64\v4.0.30319\regasm.exe

      once the registration is done, then you can use it.

      Regards
      AT

      Delete
  10. Hi,

    I am also getting the below error when registering dll. Dll is present in C drive


    C:\>C:\Windows\Microsoft.NET\Framework\v4.0.30319\regasm ATU_WindowsHandler.dll
    /codebase
    Microsoft (R) .NET Framework Assembly Registration Utility 4.0.30319.1
    Copyright (C) Microsoft Corporation 1998-2004. All rights reserved.

    RegAsm : error RA0000 : Could not load file or assembly 'file:///C:\ATU_WindowsH
    andler.dll' or one of its dependencies. Operation is not supported. (Exception f
    rom HRESULT: 0x80131515)

    your help will be appreciated.

    Thanks

    ReplyDelete
    Replies
    1. Hi,

      Use the below command.


      C:\Windows\Microsoft.NET\Framework\v4.0.30319\regasm C:\ATU_WindowsHandler.dll /codebase

      This should register the DLL.

      Regards
      AT

      Delete
    2. I have already tried that by seeing your one of the reply.
      Tried again but no success again.

      Delete
    3. Hi,

      Follow this steps
      1) open cmd and type "cd C:\Windows\Microsoft.NET\Framework\v4.0.30319" and hit enter, this will change the directory in cmd

      2) now type "RegAsm.exe C:\ATU_WindowsHandler.dll /codebase" and hit enter

      this will register the dll

      Regards
      AT

      Delete
    4. It seems some other problem.
      Same error again.

      Delete
  11. Hi Abdul Qadir,

    Open the command prompt as a administrator and than try to execute the command than you won't get the error.

    ReplyDelete
    Replies
    1. Hi Syam,

      Still facing same error.

      Delete
    2. The above command should work

      Another way doing this is
      1. Copy ATU_WindowsHandler.dll to .net framework directory
      2. Execute from cmd "RegAsm ATU_WindowsHandler.dll /codebase"

      Delete
    3. All commands that you have provided are syntactically correct. But I dont know why it's not working for me.
      Anyways thanks for the help.

      Delete
    4. Hi Abdul,

      The command you are using for registering is correct. The issue is related to security concerns.

      to resolve this try this approach: after downloading the ATU WindowsHandler dll zip file.

      >right click on the zip file
      >click on properties
      >and then click on the "Unblock" button.
      >then click on "Apply" button
      >Click ok
      >extract the zip file
      > register using the command

      Hope this works for you :)

      Regards
      AT

      Delete
    5. Thanks a lot. It solved the problem.
      Looking forward to many more utilities.

      Delete
  12. Please make the DLL as downloadable.

    ReplyDelete
  13. Hi,
    please provide access to DLL

    ReplyDelete
    Replies
    1. Hi,

      The download links are perfectly working. once you click the link you will be redirected to google drive, from this page, under file menu you have download option.

      Regards
      AT

      Delete
  14. Hey i am working on testing automation of an app Using java. i am having issues regarding the atu library. help me out.

    ReplyDelete
  15. Hi, I am trying to download the window handler dll from Google Drive, but get the following error:

    "Sorry, the owner hasn't given you permission to download this file.

    Only the owner and editors can download this file. If you'd like to download it, please contact the owner."

    Please contact me regarding this issue!

    Thanks, Nathan

    ReplyDelete
    Replies
    1. Hi Nathan,

      you can download it now :)

      Regards
      AT

      Delete
  16. When running Selenium exception shows - Please register the ATU_WindowsHandler.dll even when registered the dll succussfully. Please help

    ReplyDelete
    Replies
    1. Are you working on a 64bit OS?

      Delete
    2. Hi AT,

      Yes it is 64 bit OS. Using jacob-1.17-x64 in the system porperty and added the jacob.exe to the build path. Using ATU_WindowsHandler.dll to register and added ATU_Selenium_Utilities_2.0 to the build path.
      But when i run the Selenium test shows that ATU_WindowsHandler.dll is not registered even though in administrator cmd window it shows successfully registered. Please help me.
      Sorry for posting it twice.

      Delete
    3. Hi,

      Wat about the java version and architecture?

      Delete
    4. Hi All,

      Use jdk 1.6. It works perfect.

      The current version of Jacob library has got some problems with jdk 1.7 .

      Delete
  17. Hi AT,

    How can we handle this on linux environment.Thanls in advance!!

    ReplyDelete
    Replies
    1. Hi Aman,

      This release is targeted to supported only in Windows Environment.

      #AT

      Delete
  18. Hi AT,

    I have an issue with IE browser. When i open dialog in the browser and try to execute the code. It's is working perfectly. But when i integrate the same code to the framework. It's not happening. Is the any wait we need to introduce in between opening the dialog and entering file path? i am using c# and here is the code enter file path.

    try
    {
    FileLogger.LogFileInfo(browserTitle);
    WindowsHandler handler = new WindowsHandler();

    AutomationElement runWindowElement = handler.FindWindowByName(browserTitle);

    AutomationElement textBoxElement = handler.GetElementByNameAndClassName(runWindowElement, "File name:", "Edit");

    handler.ClearText(textBoxElement);

    handler.SendTextUsingUIAutomation(textBoxElement, filePath);

    AutomationElement openButton = handler.GetElementByNameAndClassName(runWindowElement, "Open", "Button");
    handler.InvokeElement(openButton);
    try
    {
    handler.ClickAt(openButton);
    }
    catch (Exception)
    {

    }

    return true;
    }
    catch (Exception)
    {
    return false;
    }

    ReplyDelete
    Replies
    1. Hi Sandeep,

      The scenario which you are facing is explained below.

      When a native dialog say upload dialog appears, the webdriver does not proceed to next step unless the dialog is closed, which means the next step for entering upload action does not execute.

      However you can still overcome this challenge by implementing threads - A java implementation is given in the blog, you can implement in C# in similar fashion.

      #AT

      Delete
  19. Please find the below link for selenium automation examples and tutorials.

    http://seleniumeasy.com/selenium-tutorials/selenium-automation-framework-example

    ReplyDelete
  20. Hi AT,

    I still get the following error even after trying all the solutions you provided above

    Exception in thread "main" java.lang.NoSuchFieldError: m_pDispatch
    at com.jacob.com.Dispatch.createInstanceNative(Native Method)
    at com.jacob.com.Dispatch.(Dispatch.java:101)
    at com.jacob.activeX.ActiveXComponent.(ActiveXComponent.java:58)
    at atu.utils.windows.handler.WindowHandlerWrapper.(WindowHandlerWrapper.java:22)
    at atu.utils.windows.handler.WindowHandler.(WindowHandler.java:19)
    at com.automation.methods.AUT.testUploadFileFirefox(AUT.java:27)
    at com.automation.methods.AUT.main(AUT.java:15)

    Please help

    Regards,
    Vinay

    ReplyDelete
    Replies
    1. Hi AT,

      After looking at the post http://craftingjava.blogspot.in/2012/08/javalangnosuchfielderror_9430.html it worked fine. I replaced jacob-1.14.3.jar file with jacob.jar file.

      Thanks,
      Vinay

      Delete
    2. Hi AT,

      This is excellent work, this has increased my scope of testing.
      Great Job!!!..

      Regards,
      Vinay

      Delete
    3. Can u please send me the dependencies to ATU jar files for maven POM.xml

      Delete
  21. Hi,

    Excellent job!

    Can we have a version which works on Linux also?

    Thanks,

    Rakesh

    ReplyDelete
    Replies
    1. We appreciate your response. Currently we do not have one that works on linux, we shall post it if it can be possible !

      #AT

      Delete
    2. I did a version in JS which is working fuly inside the browsers, so its working onWin/Mac/Linux with IE/FF/Safari/Chrome/Phantomjs...
      See https://github.com/rac2030/SeleniumDownloadHelper

      Delete
  22. How to put the ATU jars as a dependency in Maven projects.

    ReplyDelete
    Replies
    1. did u get any info regarding ATU jars dependency in Maven projects.if you plaese share me other wise tellme is there any alternate solution for that one

      Delete
  23. Can u please send me the dependencies to ATU jar files for maven POM.xml

    ReplyDelete
  24. Engineering students who are interested in implant training for engineering students can contact us. We provide real time implant training for engineering students
    for aspiring students.

    ReplyDelete
  25. Your description is really very nice and interesting in which there is the discussion about the status of Automation Testing. Thanks for sharing this info and please keep sharing.

    Vancouver home automation | Security vancouver | Best Security Vancouver

    ReplyDelete
  26. Wonderful! So simple. Thanks for the info, you made it easy to understand. I am sure at least once in your life you had to fill out a form. I use a simple service http://goo.gl/mwMVxN for forms filling. It definitely makes my life easier!

    ReplyDelete
  27. If you give concept with pictures it will be useful for me like beginners so please update some pictures.
    Regards,
    Deeksha

    Selenium Training in Chennai

    ReplyDelete
  28. isDisplayed() method always returning true even if element is not visible and based on that true value if I try to use getText() method its throwing ComFailException ("Invoke of: GetText") with description "Object reference not set to an instance of an object."

    ReplyDelete
  29. Selenium
    Selenium is an open source software-testing framework for Web application. It supports different populat languages like Java, Perl, PHP, C# to write domain specific scripts.
    And also Selenium providing record and playback supports to test application without learn scripting language. Selenium composes four components such as (Selenium IDE, Selenium RC, WebDriver, Selenium) a single suite for different testing purposes.
    The advantage of Selenium compare to other automation tools are it is open source, execute scripts across different browser and parallel execution
    As it is open source many of the organization are preparing this tool for automation testing.


    The scope of this tool very huge, so students, job seeker can consider this tool for thier carrier.



    For further details
    Selenium Testing training in Chennai

    ReplyDelete

  30. The biggest change in Selenium recently has been the inclusion of the WebDriver API. Driving a browser natively as a user would either locally or on a remote machine using the Selenium Server it marks a leap forward in terms of browser automation.

    Selenium WebDriver fits in the same role as RC did, and has incorporated the original 1.x bindings. It refers to both the language bindings and the implementations of the individual browser controlling code. This is commonly referred to as just "WebDriver" or sometimes as Selenium 2.
    Selenium Training Institute in Chennai

    ReplyDelete
  31. Cool! But before we can automate this we need to be able to spy on the dialogs fields in order to know what properties we can used to identify them in our Selenium script.
    Selenium Training in Chennai
    If all goes well, you should see that your script opened the example web page, clicked on the print dialog, changed some value, and then clicked on the Cancel button. (Note: you should never use Thread.Sleep in your real-world test cases – I just added it here so you could see what was happening.)
    Selenium Training in Velachery

    ReplyDelete
  32. This article is so informatic and it really helped me to know more about the Selenium Testing. This selenium article helps the beginners to learn the best training course. So keep updating the content regularly.
    Selenium Training in Chennai | Best Selenium Training institute in Chennai | Selenium Course in Chennai

    ReplyDelete
  33. That was a great message in my carrier, and It's wonderful commands like mind relaxes with understand words of knowledge by information's.
    Selenium Training in Chennai

    ReplyDelete
  34. Call +931 009 6831 : Must have Industrial Automation Training Certificate from DIAC Institute with the knowledge of PLC, SCADA, Automation, Instrumentation, Embedded Systems, Robotics, Autocad, EPLAN.

    ReplyDelete
  35. LOSYCO ist ein kompetentes, Handling spezialisiertes Unternehmen im Bereich der Produktions-Logistik. Konzipiert und realisiert werden Lean-Produktions-Systeme aus einer Hand.

    Visit Now - http://losyco.com/landingpages/handling.html

    ReplyDelete