QTP的TextUtil物件的使用
在QTP中有專門的一個物件TextUtil,可用於識別指定視窗中的文字。有時候使用其中的GetTextLocation方法可以解決某些控制元件識別和定位的問題。
The object used to recognize text within a specified window handle.
但是如果有其它方法的話,建議不要使用這種識別方式。例如,使用GetROProperty、GetVisibleText等。
When possible, it is recommended to use alternative methods of capturing text instead of using the TextUtil object. For example:
- Use the GetROProperty method or the Object property to retrieve the value of the text (or equivalent) property from an object in your application
- Use a text or text area output value step to retrieve text or a text or text area checkpoint step to verify a text value.
- Use the GetVisibleText or GetTextLocation methods of the appropriate test object.
GetText方法:
Returns the text from the specified window handle area. The area is defined by pairs of coordinates that designate two diagonally opposite corners of a rectangle.
例如:
Extern.Declare micLong,"FindWindow","User32","FindWindowA",micString,micString
hNotepad = Extern.FindWindow("Notepad", "無標題 - 記事本")
NotepadText = TextUtil.GetText(hNotepad)
MsgBox NotepadText
GetText支援查詢指定控制程式碼的視窗中的文字,也支援通過指定某個區域,例如:
MsgBox TextUtil.GetText(0, 20, 20, 200, 200)
第一個引數0表示不指定視窗,而是整個螢幕區域。
GetTextLocation方法:
Checks whether a specified text string is contained in a specified window area. If the text string is located, the location coordinates are also returned.
TextUtil.GetTextLocation(TextToFind, hWnd, Left, Top, Right, Bottom[, MatchWholeWords])
Important Information
- The text to capture must be visible in the application window when the step runs.
- This method returns True only if the the TextToFind argument value is found within a single line in the specified area. The text search restarts on each line of text.
- If the TextToFind argument value includes a space, then this method searches for that text as whole words, regardless of the value set in the MatchWholeWords argument. For example, if you search for "a b" and the text "bla bla" exists, the method will still return False. However, if the MatchWholeWords argument is set to False, then a search for "la" in an area where "bla bla" exists, would return True.
- If the text is found (return value = True) and if the Left, Top, Right, and Bottom arguments are supplied as variables, then the method also returns the exact coordinates of the specified text to the supplied arguments (the returned coordinates overwrite the supplied ones).
- The results of this method may be different depending on the settings selected in the Text Recognition pane of the Options dialog box (Tools menu > Options item > General node > Text Recognition node).
- The results of this method may be different in different run sessions depending on the operating system version you are using, service packs you have installed, other installed toolkits, the APIs used in your application, and so on. Therefore, when possible, it is highly recommended to use alternative ways retrieve the value of the text (or equivalent) property from an object in your application instead of using the GetText method, as described in the Important Information section of the TextUtil Object.
Syntax
例子:
l = -1
t = -1
r = -1
b = -1
Succeeded = TextUtil.GetTextLocation("檔案",0,l,t,r,b,false)
If Not Succeeded Then
MsgBox "Text not found"
else
x = (l+r) / 2
y = (t+b) / 2
Set dr = CreateObject("Mercury.DeviceReplay")
dr.MouseMove x,y
dr.MouseClick x, y, 0
End If
相關文章
- 使用QTP管理wap頁面物件心得小結QT物件
- QTP如何用指令碼關閉物件的智慧識別QT指令碼物件
- QTP中如何快速獲取Page中的物件個數QT物件
- QTP的Action模板QT
- 在QTP的Select方法中使用正規表示式QT
- 使用QTP進行非GUI的自動化測試QTGUI
- 在QTP中使用Eval與ExecuteQT
- Bundle物件的使用物件
- QTP讀取Excel資料的方法QTExcel
- QTP描述性程式設計-遍歷頁面多個物件QT程式設計物件
- jsoup物件的使用JS物件
- C++ 物件的使用C++物件
- 泛型物件的使用泛型物件
- QTP測試AJAX時的等待問題QT
- QTP整合SikuliQT
- 使用QTP進行WEB頁面效能測試QTWeb
- 安裝QTP後,啟動qtp程式自動退出QT
- .NET Core 物件池的使用物件
- ES6的Promise物件的使用Promise物件
- 跟小師父學習QTP後的總結QT
- WEB的QTP原型框架PAFAWEB(增強型SAFFRON)WebQT原型框架
- QTP處理驗證碼的一種方法QT
- QTP呼叫外部應用程式的4種方法QT
- QTP的智慧識別(Smart Identification)過程QTIDE
- 使用QTP的.NET外掛擴充套件技術測試ComponentOne的ToolBar控制元件QT套件控制元件
- QTP 10 破解 之路QT
- QTP連線OracleQTOracle
- AutoIt vs. QTPQT
- QTP無法錄製的控制元件的解決方法QT控制元件
- QTP測試指令碼的維護 - 使用Update執行模式和Maintenance執行模式QT指令碼模式AINaN
- 使用封裝資源的物件封裝物件
- 使用ProForm的useRef()物件的注意事項ORM物件
- TestingAnywhere - 聲稱是QTP的替代者QT
- 用Watir測試QTP的Demo程式Mercury ToursQT
- WinRunner和QTP對比QT
- QTP問與答(轉)QT
- RFT和QTP與AutoItQT
- QTP關鍵技術QT