Object Identification Center for Selenium
When writing a Selenium test, use the LeanFT Object Identification Center (OIC) for Selenium to inspect elements in your application, find the optimal way to identify those elements, and generate selenium-based element identification code to use in your scripts.
The OIC for Selenium is supported for Selenium projects on Windows, Linux, and Mac environments. it is not supported for Safari browser (on Mac). However, you can use the LeanFT extended Selenium locators and utilities when running Selenium tests in Safari.
Note: The OIC for Selenium is available with any supported LeanFT license, excluding the UFT Runtime license.
Spy your application to uniquely identify an element.
Perquisite: Make sure that your browsers and WebDriver drivers are set up, as described in Before you start.
To spy your application
Launch the OIC in one of the following ways:
From your IDE menu. Click LeanFT > Selenium > Object Identification Center.
You can also open it in standalone mode:
Windows From the Start menu, open (Micro Focus > Micro Focus LeanFT > Tools > Selenium > Object Identification Center. Linux/Mac Open the Tools folder from the LeanFT installation folder, and then run ./oic-selenium.
Click the Browser Launcher button to select and launch a browser.
The browser you selected opens.
In the Object Identification Center window, click the Start spying button.
The Object Identification Center window is moved to the background.
When you hover over elements in your application, each element is highlighted and a tooltip displays some basic information about it.
On the left of the Object Identification Center window, the hierarchy tree displays the element's full hierarchy.
On the right, the OIC displays the full list of supported locators for the selected element, and the current values captured from your application.
Tip: To find the element in the application that corresponds to an element in the OIC hierarchy tree, hover over the element's node in the hierarchy tree, and click the Highlight button.
In some cases you may need to use an element higher up in the hierarchy to identify an element. In such cases, select the check boxes next to the relevant elements in the hierarchy.
On the right, select the locator or locators that you want to use to identify the element.
You can modify the values for any selected locator. To enter a regular expression value for a string, click the Set as Regular Expression asterisk to the right of the value box. For more details, see Regular expression guidelines.
Click the Validate button on the OIC toolbar to validate your new test object identification.
LeanFT searches the application for element that match the element's locator in the OIC.
Matching elements are highlighted in your application. A message displays how many matches were found. If more than 20 matched are found, the elements are not highlighted in the application.
Note: To stop spying, press the Esc key while focused inside the browser.
- If no matches are found, or if multiple matches are found, adjust the set of locators that you selected and their values, and validate again. Repeat until you get a unique match.
Generate element identification code
After you have spied an element and validated it, you can generate code for it and paste the code into your test script.
To generate code
In the OIC toolbar, click the Generate code to clipboard button. Code identifying the element is generated and copied to the clipboard.
The default language in Eclipse, Spring Tool Suite, IntelliJ IDEA, and Android Studio is Java. In Visual Studio, the default language is C#. However, you can change the setting to any language supported on your IDE.
To change language, click the Settings button and select a language. The selection is saved and used for all subsequent code generations.
In your IDE, paste the code into your test script.
When you paste the generated code, the browser parent element is called driver. If you assigned a different name to your browser element, modify as needed in the pasted code.
Capture an image of the element in your application that corresponds to the currently selected element in the OIC.
To capture an image
Make sure no other application is covering any part of your application while performing the image capture.
- Firefox/IE users: Make sure that the tab containing the element is in focus.
In the Object Identification Center window, make sure the element you want to capture is in focus in the hierarchy tree.
- In the OIC toolbar, click the Capture object image button.
The Save File dialog box opens.
- In the Save File dialog box, save the image to a location of your choice.