Text recognition methods enable you to conveniently interact with test applications that contain highly customized controls, which cannot be identified using object recognition. You can use
text clicks instead of coordinate-based clicks to click on a specified text string within a control.
For example, you can simulate selecting the first cell in the second row of the following table:
Specifying the text of the cell results in the following code:
table.textClick("Brian Miller");
Text recognition methods are supported for the following technology domains:
- Win32.
- WPF.
- Windows Forms.
- Java SWT and Eclipse.
- Java AWT/Swing.
Note: For Java Applets, and for Swing applications with Java versions prior to version 1.6.10, text recognition is supported out-of-the-box. For Swing applications with Java version 1.6.10 or later, which do not support Direct3D, you have to add the following command-line element when starting the application:
-Dsun.java2d.d3d=false
For example:
javaw.exe -Dsun.java2d.d3d=false -jar mySwingApplication.jar
Text recognition is not supported for Java Applets and Swing applications that support Direct3D.
- Internet Explorer.
Note: Text recognition does not work with controls that are not visible on the screen. For example, you cannot use text recognition for a text that is scrolled out of view.
Note: Text recognition might not work if the font that is used in the target text is not installed on the machine on which the test is executed.
Text recognition methods
The following methods enable you to interact with the text of a control:
- TextCapture
- Returns the text that is within a control. Also returns text from child controls.
- TextClick
- Clicks on a specified text within a control. Waits until the text is found or the
Object resolve timeout, which you can define in the synchronization options, is over.
- TextRectangle
- Returns the rectangle of a certain text within a control or a region of a control.
- TextExists
- Determines whether a given text exists within a control or a region of a control.
Text click recording
When text click recording is enabled,
Silk4J records
TextClick methods instead of clicks with relative coordinates. Use this approach for controls where
TextClick recording produces better results than normal coordinate-based clicks. You can insert text clicks in your script for any control, even if the text clicks are not recorded.
If you do not whish to record a
TextClick action, you can turn off text click recording and record normal clicks.
The text recognition methods prefer whole word matches over partially matched words.
Silk4J recognizes occurrences of whole words previously than partially matched words, even if the partially matched words are displayed before the whole word matches on the screen. If there is no whole word found, the partly matched words will be used in the order in which they are displayed on the screen.
Example
The user interface displays the text
the hostname is the name of the host. The following code clicks on
host instead of
hostname, although
hostname is displayed before
host on the screen:
control.textClick("host");
The following code clicks on the substring
host in the word
hostname by specifying the second occurrence:
control.textClick("host", 2);