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

How can I identify all of the objects and locators string for a currently opened Web Page?

How can I identify all of the objects and locators string for a currently opened Web Page?

Occasions may arise where you need to identify either all or a particular child object of a HTML page at runtime. The following code below demonstrates how you can do this using the SilkTest Open Agent.

 

[ ] // Formating function which creates a valid X-Path Query

[-] string formatLocatorString(LIST OF STRING lsLocator)

                [ ] string sPart, sLocator =""

                [-] for each sPart in lsLocator

                                [ ] sLocator = "{sLocator}{sPart}"

                [ ] return sLocator

[ ]

[ ] // Function to query WebPage for all child Dom objects

[-] GetWindowsAndClasses (WINDOW wWindow)

                                [ ] LIST OF WINDOW lwWndList

                                [ ] WINDOW wTemp

                                [ ] WINDOW wParent

                                [ ] lwWndList = wWindow.FindAll("//*")

                                [ ] 

                                [ ] print("------List of Parent Object Names, Child Object Names and associated Locator X-Path -----")

                                [ ] print(" ")

                                [-]  for each wTemp in lwWndList

                                                [ ] wParent = wTemp.GetParent()

                                                [ ] print("Parent Class Name = {wParent.GetClass()}")

                                                [ ] print("                             Class Name = {wTemp.GetClass()}")

                                                [ ] print("                             Locator Name = {formatLocatorString(wTemp.GenerateLocator())}")

                                                [ ] print(" ")

                               

 

[ ]

[-] testcase Test1 () appstate none

                [-] recording

                                [ ] Window wWin

                                [ ] wWin = Desktop.Find("/BrowserApplication//BrowserWindow")

                                [ ] GetWindowsAndClasses(wWin)

                                [ ]

 

 

Once the function GetWindowsAndClasses() is executed against any Open Web Page it will return the Parent HTML/DOM Class Name, the Child Class Name and the associated X-Path Query Locator string which can be used to identify the object, like so:

 

[-] Testcase Test1 - Passed

                [ ] ------List of Parent Object Names, Child Object Names and associated Locator X-Path -----

                [ ] 

                [ ] Parent Class Name = BrowserWindow

                [ ]                            Class Name = DomElement

                [ ]                            Locator Name = /BrowserApplication//BrowserWindow/HTML

                [ ] 

                [ ] Parent Class Name = DomElement

                [ ]                            Class Name = DomElement

                [ ]                            Locator Name = /BrowserApplication//BrowserWindow//HEAD

                [ ] 

                [ ] Parent Class Name = DomElement

                [ ]                            Class Name = DomElement

                [ ]                            Locator Name = /BrowserApplication//BrowserWindow//TITLE

                [ ] 

                [ ] Parent Class Name = DomElement

                [ ]                            Class Name = DomElement

                [ ]                            Locator Name = /BrowserApplication//BrowserWindow//META[@content='text/html; charset=i*']

                [ ] 

                [ ] Parent Class Name = DomElement

                [ ]                            Class Name = DomElement

                [ ]                            Locator Name = /BrowserApplication//BrowserWindow//META[@name='GENERATOR']

 

 

 

 

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-03-05 10:06
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.