在RFT中查詢視窗中指定名稱的物件
startApp ( "calc" );
sleep (3);
IWindow parent = getTopWindowWithCaption( "計算器" , true );
parent.activate();
IWindow btn_1 = getChildWindowWithText(parent, "1" , true , false );
btn_1.click();
IWindow btn_add = getChildWindowWithText(parent, "+" , true , false );
btn_add.click();
btn_1.click();
IWindow btn_equal = getChildWindowWithText(parent, "=" , true , false );
btn_equal .click();
getTopWindowWithCaption函式 根據指定的標題查詢頂層視窗。
getChildWindowWithText函式如下,其作用是給定一個視窗物件,查詢其中的指定名稱的物件:
/**
* Given a particular context, find a child with the specified text.
* Typically this is used to locate a pushbutton with specific text
* on it, such as "OK" or "Cancel".
*
* @param parent The context from which the search is based, typically
* a top level window like a dialog box.
* @param text The text on the window being sought.
* @param ignoreCase <code> true </code> if the case of the text should not
* be taken into consideration.
* @param onlyImmediateChildren <code> true </code> if the search should be
* limited to only the children of the parent
* window and not recurse into the grandchildren .
* @return The control with the specified text or <code> null </code> if no
* child with the text is located.
*/
public IWindow getChildWindowWithText(IWindow parent,
String text,
boolean ignoreCase,
boolean onlyImmediateChildren)
{
if ( text == null )
return null ;
IWindow[] children = ( parent != null ? parent.getChildren() : null );
int length = ( children != null ? children. length : 0 );
for ( int i = 0; i < length; ++i )
{
IWindow child = children[i];
String childText = child.getText();
if ( ( !ignoreCase && text.equals(childText) ) ||
( ignoreCase && text.equalsIgnoreCase(childText) ) )
return child;
if ( !onlyImmediateChildren )
{
IWindow grandchild = getChildWindowWithText(child, text, ignoreCase, onlyImmediateChildren);
if ( grandchild != null )
return grandchild;
}
}
return null ;
}
以下是支援正規表示式的版本:
/**
* Given a particular context, find a child with text that matches the
* specified regular expression pattern.
* Typically this is used to locate a pushbutton with specific text
* on it, such as "OK" or "Cancel" when the format of the text is not specific
* (for instance when the text equals " OK " instead of a simple "OK").
*
* @param parent The context from which the search is based, typically
* a top level window like a dialog box.
* @param pattern The pattern for the text on the window being sought.
* @param ignoreCase <code> true </code> if the case of the text should not
* be taken into consideration.
* @param onlyImmediateChildren <code> true </code> if the search should be
* limited to only the children of the parent
* window and not recurse into the grandchildren .
* @return The control with the specified text or <code> null </code> if no
* child with the text is located.
*/
public IWindow getChildWindowWithTextPattern(IWindow parent,
String pattern,
boolean ignoreCase,
boolean onlyImmediateChildren)
{
Regex regex = ( ignoreCase ? new Regex(pattern, Regex. MATCH_CASEINDEPENDENT ) :
new Regex(pattern) );
IWindow[] children = ( parent != null ? parent.getChildren() : null );
int length = ( children != null ? children. length : 0 );
for ( int i = 0; i < length; ++i )
{
IWindow child = children[i];
String childText = child.getText();
if ( regex.matches(childText) )
return child;
if ( !onlyImmediateChildren )
{
IWindow grandchild = getChildWindowWithText(child, pattern, ignoreCase, false );
if ( grandchild != null )
return grandchild;
}
}
return null ;
}
相關文章
- 在RFT中根據指定的標題查詢頂層視窗
- 在RFT中關閉所有IE瀏覽器視窗的3種方法瀏覽器
- 在RFT中新增clipboard檢查點
- 刪除指定名稱的程式
- 物件點查詢和中括號查詢的區別物件
- 在RFT中新增檔案檢查點
- Finder Windows for Mac(訪達視窗查詢器)WindowsMac
- 實用的Finder視窗查詢器:Finder Windows for MacWindowsMac
- 一文讀懂TDengine的視窗查詢功能
- JavaScript中的Window物件(開啟新的視窗)JavaScript物件
- js查詢HTMLCollection物件中的下標JSHTML物件
- 常見物件-在大串中查詢小串出現的次數案例物件
- windows上殺掉指定名稱的程式Windows
- C#中關閉子視窗而不釋放子視窗物件的方法C#物件
- 由allocation_unit_id查詢其所屬物件名稱物件
- 在 with 查詢中只查詢個別欄位
- 批量建立指定名稱資料夾
- 在RFT中如何獲取JTable中的所有資料?
- js實現在彈出視窗中重新整理主視窗JS
- 在RFT中如何通過指令碼獲取已新增到某個指令碼中的測試物件?指令碼物件
- 記如何在預載入中指定查詢的欄位
- OQL(物件查詢語言)在產品實現中造成的RCE(Object Injection)物件Object
- es中如何使用巢狀物件查詢巢狀物件
- 在Mac中如何用⌘鍵拖拽非使用中的視窗?Mac
- 在畫中畫視窗中安裝 React 元件React元件
- 檢視檔名稱和查詢檔案中所含字串字串
- 在 Linux 中查詢 CPU 的核數Linux
- 在 CTreeCtrl 中列舉系統中的所有視窗!(I) (轉)
- 在 CTreeCtrl 中列舉系統中的所有視窗!(II) (轉)
- 父視窗和iframe中物件互相傳值簡介物件
- RAC:在子查詢使用gv$檢視,有時查詢不出資料
- js如何判斷指定名稱的函式是否存在JS函式
- 在非主執行緒中建立視窗執行緒
- Linux裝置名稱的查詢Linux
- 【emWin】例程二十:視窗物件——Dropdown物件
- 【emWin】例程十七:視窗物件——Button物件
- 【emWin】例程三十:視窗物件——Multiedit物件
- jQuery在子視窗如何操作父視窗元素jQuery