Saturday, 19 April 2014

Handling Windows Dialogs Using Selenium Part4

This section describes some of the important API methods and their usage.


//The initial method to interact with a main window
public WindowElement getWindowElement(String windowName)
                     throws WindowsHandlerException


//To Check whether a particular window is present
public boolean isWindowPresent(String windowName) 


//To see whether an element is displayed on screen (Visible on screen)
public boolean isDisplayed(WindowElement element) 


//To determine whether an element is enabled to interact
public boolean isEnabled(WindowElement element)
                     throws WindowsHandlerException 


//To check whether an element is found
public boolean isNull(WindowElement element) 


//Retrieve Text Box Content
public String getTextBoxValue(WindowElement element)


//Get text of an Element
public String getText(WindowElement element)


//Search for Installed browser Version, Pass the Browser Enum as parameter
public String getInstalledBrowserVersion(Browser browser)
                     throws WindowsHandlerException 


//Start/Run/Open an application
public boolean openApplication(String appPath) 


//Close Process safely as a user would close it.
//Identify the process by id or multiple process by same name
//If the process cannot be closed in a natural way - kill the process
public void closeProcessesByName(String name, boolean forceKill)
public void closeProcessesByID(int pid, boolean forceKill)



//Search an element by following methods
public WindowElement findElementByAccessKey(WindowElement parentElement,
                     String accessKey) throws WindowsHandlerException


public WindowElement findElementByClassNameAndLocalizedControlType(
                     WindowElement parentElement, String className,
                     String localizedControlTypeName) throws WindowsHandlerException

public WindowElement findElementByAutomationID(WindowElement parentElement,
                     String automationID) throws WindowsHandlerException 

public WindowElement findElementByNameAndLocalizedControlType(
                     WindowElement parentElement, String name,
                     String localizedControlTypeName) throws WindowsHandlerException 

public WindowElement findElementByClassName(WindowElement parentElement,
                     String className) throws WindowsHandlerException

public WindowElement findElementByNameAndClassName(
                     WindowElement parentElement, String name, String className)
                     throws WindowsHandlerException


public WindowElement findElementByLocalizedControlType(
                     WindowElement parentElement, String localizedControlTypeName)
                     throws WindowsHandlerException

public WindowElement findElementByName(WindowElement parentElement,
                     String name) throws WindowsHandlerException 





Find Multiple Elements by
public List<WindowElement> findElementsByLocalizedControlType(
                     WindowElement parentElement, String localizedControlTypeName) 


To Be Contd..

51 comments:

  1. Your information about software testing is really interesting. Also I want to know the latest new techniques which are implemented in software testing. Can you update it in your website.

    ReplyDelete
  2. Hi AT,

    Can i use regular expression for windowName in getWindowElement(String windowName)
    ex : getWindowElement("* - Windows Internet Explorer")

    Regards,
    Vinay

    ReplyDelete
    Replies
    1. Hello Vinay,

      Regular Expressions are not supported yet.

      #AT

      Delete
    2. Thanks for the reply, are there any plans in future?

      ~Vinay

      Delete
    3. please log your requests in the below page.

      https://docs.google.com/spreadsheet/ccc?key=0ArrZvkq9tkwPdEpfa0tFN0RIQ0ZyXy1mSGZPdzl4MVE&usp=drive_web#gid=5

      #AT

      Delete
  3. Hi AT,


    Through code i run the following :
    {{
    line1 : ffElement = handler.getWindowElement("Import Controls & Questionnaires - Mozilla Firefox");
    line2 : handler.setFocus(ieElement);
    line3 : WindowElement uploadElement = handler.findElementByName(ffElement ,"Choose File to Upload");
    line4 : WindowElement fileNamePath = handler.findElementByNameAndClassName(uploadElement, "File name:", "Edit");

    }}

    in the above code after line2 the dialog comes to the front at line3 i get the following error :
    {{
    [ATU Windows Handler Framework Exception] The Given Parent Element is null, Consider Checking the Parent Element's Identification parameters
    }}


    Using UISpy when i select "Set Focus" i get the following error :

    {{
    Exception
    Time Stamp:6/10/2014 8:01 PM
    Element:"window" "Import Controls & Questionnaires - Mozil..."
    Name:InvalidOperationException
    Message:Target element cannot receive focus.
    Stack Trace: at System.Windows.Automation.AutomationElement.SetFocus()
    at UISpy.Base.Node.SetFocus()

    }}

    though the element is present.

    Note : It is specific to one dialog, this code works fine on other dialogs. Not sure what attributes it is unable to find.


    Please let me know if you need any additional information using UISpy

    Appreciate your help.

    Regards,
    Vinay

    ReplyDelete
    Replies
    1. UISpy message indicates the element cannot receive focus. It is not necessary that UISpy must work on all the elements perhaps the developers of the Dialog may have restricted the element to be visible or the element is actually hidden and cannot receive focus - another element might be overlapping on this element (such as pane).

      #AT

      Delete
    2. Hi AT,

      Thanks for your kind reply.

      I tried to change the browser attributes and i was able to get the focus of all the elements in Upload Dialog box using UISpy, but when i run the java code i get the same error after executing line3 (code in my previous comments), if you notice line2 executes fine and the focus is set to the Browser.
      {{
      [ATU Windows Handler Framework Exception] The Given Parent Element is null, Consider Checking the Parent Element's Identification parameters
      }}

      Are there any specific attributes that handler.findElementByName looks for, if you could please tell me i will modify them and try again.

      Appreciate your help.

      Regards,
      Vinay

      Delete
    3. Vinay,

      "getWindowElement" is used to identify the main window (Parent window). In your code ""Import Controls & Questionnaires - Mozilla Firefox"" is this the name of the upload dialog ?

      If so, then first identify the Firefox browser main window using "getWindowElement", then try to find upload dialog.

      WindowHandler handler = new WindowHandler();
      WindowElement firefoxElement = handler
      .getWindowElement("Firefox Main Window name");
      WindowElement uploadDialog = handler.findElementByName(firefoxElement,
      "File Upload Dialog Name");

      #AT

      Delete
    4. Hi AT,

      I tried the same steps as you said, additionally i added another step to make sure the parent window is identified after
      -WindowElement firefoxElement = handler
      .getWindowElement("Firefox Main Window name");
      -handler.setFocus(firefoxElement );
      after executing this step the firefox window comes to the Front.
      and then after executing the below step the script fails with the exception Parent element is null
      -WindowElement uploadDialog = handler.findElementByName(firefoxElement,
      "File Upload Dialog Name");

      Regards,
      Vinay

      Delete
    5. Hi AT

      Thanks for your support, i just figured out the issue, it was caused because of special character '&' in the 'Name', i guess if you extend your support to accept special character it would be excellent.

      Regards,
      Vinay

      Delete
    6. Hi AT

      I have kind of question target element cannot receive focus but here am automating on excel using win32ole and RAutomation gem am using ruby and cucumber. Using win32 and msuia adapter for find the element here am attaching autoit window info
      >>>> Window <<<<
      Title:Book1 - Excel
      Class:XLMAIN
      Position:-9, -9
      Size:1938, 1050
      Style:0x17CF0000
      ExStyle:0x00010110
      Handle: 0x000908D4

      >>>> Control <<<<
      Class:ATL:66E99690
      Instance:6
      ClassnameNN:ATL:66E996906
      Name:Advanced (Class):[CLASS:ATL:66E99690; INSTANCE:6]
      ID:256
      Text:More>>
      Position:1656, 975
      Size:248, 20
      ControlClick Coords:30, 12
      Style: 0x56010000
      ExStyle:0x00000000
      Handle: 0x000C0

      Any workaround appreciated your help.

      Delete
  4. Thank you for sharing good information. I liked your blog, keep posting. I am from Indium software is an independent testing company that provides both Outsourced/In-house Manual & regression test automation testing services across the world. Testing & enhance the performance of your desktop, mobile or web application under load and stress.

    ReplyDelete
  5. I have the same problem
    [ATU Windows Handler Framework Exception] The Given Parent Element is null, Consider Checking the Parent Element's Identification parameters
    at atu.utils.windows.handler.WindowHandler.findElementByNameAndLocalizedControlType(WindowHandler.java:158)
    at com.seleniummaster.agent.ReportInfoCenter1.testTomcatAuthenticationInFirefox(ReportInfoCenter1.java:71)
    ...............................

    ReplyDelete
  6. we provide our valued clients a comprehensive portfolio of new age IT consulting services that streamline their process, help them manage change, innovate newer opportunities for maximizing profit and best of all assist build a credible brand.

    ReplyDelete
  7. Really awesome blog. Thanks for sharing this informative blog. Suppose if anyone want to learn Software Testing Training in Chennai at a reputed training institutes. If you are looking for best Software Testing Training Institutes in Chennai reach FITA located at Chennai, India. Rated as No.1 placement and training center in Chennai.

    ReplyDelete
  8. Hi, I wish to be a regular contributor of your blog. I have read your blog. Your information is really useful for beginner. I did QTP Training in Chennai at Fita training and placement academy which offer best Software Testing Training in Chennai with years of experienced professionals. This is really useful for me to make a bright career.

    ReplyDelete
  9. The future of software testing is on positive note. It offers huge career prospects for talented professionals to be skilled software testers. Automation training in Chennai | Software training | Software testing training institute Chennai

    ReplyDelete
  10. very nice !!! i have to learning a lot of information for this sites...Sharing for wonderful information.
    CCNA training in chennai | CCNA training chennai | CCNA course in chennai | CCNA course chennai

    ReplyDelete
  11. This site provides good information about mobile app testing. If anyone wants to know the basics of mobile app testing then this is the right blog for them. mobile application testing training in Chennai | mobile application testing training

    ReplyDelete
  12. Oracle DBA Training in Chennai
    Thanks for sharing this informative blog. I did Oracle DBA Certification in Greens Technology at Adyar. This is really useful for me to make a bright career..

    ReplyDelete
  13. Whatever we gathered information from the blogs, we should implement that in practically then only we can understand that exact thing clearly, but it’s no need to do it, because you have explained the concepts very well. It was crystal clear, keep sharing..
    Websphere Training in Chennai

    ReplyDelete
  14. Data warehousing Training in Chennai
    I am reading your post from the beginning, it was so interesting to read & I feel thanks to you for posting such a good blog, keep updates regularly..

    ReplyDelete
  15. Selenium Training in Chennai
    Wonderful blog.. Thanks for sharing informative blog.. its very useful to me..

    ReplyDelete
  16. Oracle Training in chennai
    Thanks for sharing such a great information..Its really nice and informative..

    ReplyDelete
  17. SAP Training in Chennai
    This post is really nice and informative. The explanation given is really comprehensive and informative..

    ReplyDelete
  18. This information is impressive..I am inspired with your post writing style & how continuously you describe this topic. After reading your post, thanks for taking the time to discuss this, I feel happy about it and I love learning more about this topic
    Android Training In Chennai In Chennai

    ReplyDelete
  19. Pretty article! I found some useful information in your blog, it was awesome to read, thanks for sharing this great content to my vision, keep sharing..
    Unix Training In Chennai

    ReplyDelete
  20. I found some useful information in your blog, it was awesome to read, thanks for sharing this great content to my vision, keep sharing..
    SalesForce Training in Chennai

    ReplyDelete
  21. There are lots of information about latest technology and how to get trained in them, like Best Hadoop Training In Chennai in Chennai have spread around the web, but this is a unique one according to me. The strategy you have updated here will make me to get trained in future technologies Hadoop Training in Chennai By the way you are running a great blog. Thanks for sharing this blogs..

    ReplyDelete
  22. This is really an awesome article. Thank you for sharing this.It is worth reading for everyone. Visit us:
    Oracle Training in Chennai

    ReplyDelete
  23. very nice blogs!!! i have to learning for lot of information for this sites...Sharing for wonderful information.Thanks for sharing this valuable information to our vision. You have posted a trust worthy blog keep sharing.Oracle DBA Training in Chennai

    ReplyDelete
  24. Wonderful tips, very helpful well explained. Your post is definitely incredible. I will refer this to my friend.SalesForce Training in Chennai

    ReplyDelete
  25. I have finally found a Worth able content to read. The way you have presented information here is quite impressive. I have bookmarked this page for future use. Thanks for sharing content like this once again. Keep sharing content like this.

    Software testing training in chennai | Software testing training | Software testing institute in chennai

    ReplyDelete
  26. Really awesome blog. Your blog is really useful for me. Thanks for sharing this informative blog. Keep update your blog.
    Oracle Training In Chennai

    ReplyDelete
  27. I am reading ur post from the beginning, it was so interesting to read & i feel thanks to you for posting such a good blog, keep updates regularly.Best Hadoop Training Institute In Chennai

    ReplyDelete
  28. very nice AT!!! Thanks for sharing such a nice information. Here i am stuck with an exception could you please help me out.
    Getting Error:
    [ATU Windows Handler Framework Exception] The Given Parent Element is null, Consider Checking the Parent Element's Identification parameters.

    Even though parent element is not null

    ReplyDelete
  29. Great discussion and inform on where is web design going in 2016. Each and every year web design is growing and plenty of innovative and impressive things are shared and published every day.design services

    ReplyDelete
  30. Thanks for sharing great information in your blog. Got to learn new things from your Blog . It was very nice blog to learn about Selenium.
    Selenium

    ReplyDelete
  31. Thanks a lot AT!! ,your blog is awesome, has got very valuable information. I got know more about how to identify windows objects which i was searching from long time. It solved my automation problem..

    ReplyDelete
  32. Well explained. Got to learn new things from your Blog on Appium.Appium training in chennai

    ReplyDelete
  33. Great efforts put it to find the list of articles useful for Selenium, Definitely will share the same to other forums.
    We are also one of the best sources to learn Selnium -Selenium training in Chennai | Best Selenium training institute in Chennai

    ReplyDelete
  34. It is amazing and wonderful to visit your site.Thanks for sharing this information,this is useful to me...
    Android Training in Chennai
    Ios Training in Chennai

    ReplyDelete
  35. Hi,
    Can anyone help me to handle WindowElements which has same attributes. That is both window elements are having same AutomationID and other attributes are also same.
    Appreciate your help.

    ReplyDelete