Having problems with your account or logging in?
A lot of changes are happening in the community right now. Some may affect you. READ MORE HERE

Writing the locators and properties of all recognized controls to a file in Silk4J

Writing the locators and properties of all recognized controls to a file in Silk4J

The following example Java method will retrieve a list of all the controls that the Open Agent can recognize and then iterate through each control in the list to generate:

  • the controls locator
  • the property list for each control
  • the values of each property in the said property list

The code to perform the above is as follows:

public static void printAllLocatorsAndProps(String sFile){
     List<TestObject> allWins = desktop.findAll("//*");
     try{
          FileWriter fsStream = new FileWriter(sFile);
          BufferedWriter out = new BufferedWriter(fsStream);

          for(int i=0; i<allWins.size(); i++){
               out.write(allWins.get(i).generateLocator());out.newLine();
               List<String> props = allWins.get(i).getPropertyList();

               for(int p=0; p<props.size(); p++){
                   try{
                        out.write(" "+props.get(p)+":"+allWins.get(i).getProperty(props.get(p)));out.newLine();
                   }
                   catch(Exception e){
                        out.write(" "+props.get(p)+": Not Supported");out.newLine();
                   }
          }

          out.close();
          fsStream.close();
     }
     catch(Exception e){
          e.printStackTrace();
     }
}

The above method accepts a String argument that should represent the file to which the locators and properties should be written. For example, the above method could be called in the following fashion:

printAllLocatorsAndProps("C:\\testLocProp.txt");

With the output written in the following format:

/BrowserApplication
     Application: C:\Program Files (x86)\Internet Explorer\iexplore.exe
     Background: (red: 255, green: 255, blue: 255, alpha: 255)
     browsertype: Internet Explorer
     caption: Google
     Enabled: true
     Font: System
     Foreground: (red: 0, green: 0, blue: 0, alpha: 255)
     NativeHandle: 4133296
     Text: Google - Windows Internet Explorer
     Value: Google - Windows Internet Explorer
     Visible: true
     windowClassName: IEFrame
     WindowState: 2

DISCLAIMER:

Some content on Community Tips & Information pages is not officially supported by Micro Focus. Please refer to our Terms of Use for more detail.
Top Contributors
Version history
Revision #:
1 of 1
Last update:
‎2013-10-30 19:30
Updated by:
 
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.