您的位置:軟件測(cè)試 > 開源軟件測(cè)試 > 開源功能測(cè)試工具 >
WatiN中所有的控件以及控件的識(shí)別方法
作者:網(wǎng)絡(luò)轉(zhuǎn)載 發(fā)布時(shí)間:[ 2013/12/4 13:43:34 ] 推薦標(biāo)簽:

在WatiN的源代碼中可以看到所有的控件識(shí)別設(shè)計(jì)類都是在繼承了與element相關(guān)的類
包括Element, ElementAttributeBag, ElementCollection, ElementContainer, ElementSupport, ElementTag。
首先來看Element的類可以看到它繼承IAttributeBag類,在Elemental類中寫到的方法有:
1. Classname: Get the name of the stylesheet class assigned to this element;得到傳輸給此控件默認(rèn)格式類的名稱。返回值為string.
2. Complete: Boolean Value, Get a value indicating whether the element is completely loaded;得到一個(gè)波爾值,查看是否此對(duì)當(dāng)前控件的操作完全加載。返回值為波爾值.
3. Enabled: Get a Value indicating whether this element is enabled.得到一個(gè)波爾值來確認(rèn)當(dāng)前的控件是否是可用的.返回值為波爾值.
4. ID: Get the if of this element as specified in the HTML ,返回當(dāng)前控件在此HTML頁面中的識(shí)別ID, 返回值為string。
5.TEXT: Get the inner text of this element(or all the inner text of all the elements contained in this elment). 返回當(dāng)前控件中的文本,或者是返回當(dāng)前控件所包含的控件中的所有文本,返回值為string.
6.TextBefore: Returns the text displayed before this element when it’s wrapped in a Label element, otherwise it returns null. 返回當(dāng)前控件前面的Label的文本內(nèi)容,如果當(dāng)前控件前面的控件不是Label則返回null, 返回值為string.
7. InnerHtml: Gets the inner HTML of this element. 返回當(dāng)前控件的內(nèi)部HTML代碼。返回值不用說當(dāng)然為string.
8. OuterText: Gets the outer text, 返回外部文檔,返回值為string.
    Shit,這個(gè)控件我還真不知道怎么用,呵呵。查了一下解釋如下:
InnerText:不包括標(biāo)志,標(biāo)志以內(nèi)的純文本  
  OuterText:包括標(biāo)志,連標(biāo)記及標(biāo)志內(nèi)的文本  
  InnerHtml:不包括標(biāo)志,標(biāo)志以內(nèi)的Html內(nèi)容  
  OuterHtml:包括標(biāo)志,連標(biāo)記及標(biāo)志內(nèi)的Html內(nèi)容
9. TagName: Gets the tag name of this element 返回當(dāng)前控件的標(biāo)簽。返回值為string.
10. Title: Get the title. 返回當(dāng)前頁面的標(biāo)題。返回值為stieng.
11. NextSibling: Gets the next sibling of this element in the Dom of the HTML page.返回當(dāng)前標(biāo)簽在此HTML頁面Dom控件中的下一個(gè)兄弟控件。返回值為控件即(element)
12. PreviousSibling: Gets the previous sibling of this element in the Dom of the HTML page. 返回當(dāng)前標(biāo)簽在此HTML頁面Dom控件中的下一個(gè)兄弟控件,返回值為控件即(element)。
13. Parent: Gets the parent element of this element, If the parent type is known you can cast it to that type. 返回當(dāng)前控件的父級(jí)控件,如果父級(jí)的控件類型知道,可以定義一個(gè)和父級(jí)同類型的變量控件。返回類型為控件(element).這個(gè)比較難理解,下面是舉例:
      Div
        a id="watinlink" href="http://watin.sourceforge.net" /
                  a href="http://sourceforge.net/projects/watin" /
        Div
      上面的HTML所示第二個(gè)超鏈接沒有id,如何點(diǎn)擊它來實(shí)現(xiàn)超鏈接?這時(shí)可以使用Parent這個(gè)方法:
         首先定義一個(gè)變量Div,然后把這兩個(gè)超鏈接所在的div賦值給這個(gè)Division變量。
  Div watinDiv = ie.Link(“watinlink”).Parent;
然后去找第二個(gè)Link, 可以把第一個(gè)Link看做是Links[0],那么第二個(gè)Link是Link[1]
watinDiv.Links[1].Click();
14.Style: Style is the element’s style, 返回當(dāng)前控件的格式。返回類型為Style.
  15.GetAttributeValue: This method can be used is the attribute is not available as a property of the element of a subclass of the element. Need a parameter’attributeName’, this parameter should be the name of the property exposed by IE on it’s element object. The return is the value of the attribute if available, otherwise null is returned. 當(dāng)控件的屬性不存在或者或者屬性屬于此控件的一個(gè)子類時(shí)此方法可以使用。但是需要傳遞給此方法一個(gè)參數(shù)即屬性名稱(它應(yīng)該是被IE暴露的一個(gè)空間實(shí)體),返回值為控件的屬性值或者為null.
   16. ToString: Returns a string that represents the current object, or null.返回代表當(dāng)前實(shí)體的值,如果沒有則返回空。返回類型為string.
   17.Click: Click this element and waits till the event is completely finished(Page is loaded and ready). 點(diǎn)擊當(dāng)前控件然后等待,知道整個(gè)事件完成即:頁面被完全加載。無返回值.
   18.ClickNoWait: Click this instance and returns immediately. Use this method when you want to continue without waiting for the click event to be finished. Mostly used when a HTML Dialog is displayed after clicking the element. 觸發(fā)事件并立刻返回信息然后去判斷需要如何執(zhí)行,通常是在點(diǎn)擊或者跳轉(zhuǎn)頁面還沒完成時(shí)你需要其它操作。一般情況下是在當(dāng)彈出對(duì)話框時(shí)使用這個(gè)方法。無返回值。
   19.Focus: Gives the input focus to this element. 聚焦在當(dāng)前這個(gè)輸入控件,我不是很明白這個(gè)方法。無返回值。
   20.DoubleClick: Doubleclicks this element. 雙擊當(dāng)前的控件。無返回值。
   21.KeyDown, KeyPress, KeyUp 三個(gè)方法分別為按下鍵盤不放, 按一下鍵盤,和松開按鍵盤。很繞口. 這個(gè)應(yīng)該是從.Net繼承的。
   22. Blur: Fires the blur event on this element. 這個(gè)應(yīng)該是和focus相反的方法。取消對(duì)這個(gè)控件的focus.

軟件測(cè)試工具 | 聯(lián)系我們 | 投訴建議 | 誠聘英才 | 申請(qǐng)使用列表 | 網(wǎng)站地圖
滬ICP備07036474 2003-2017 版權(quán)所有 上海澤眾軟件科技有限公司 Shanghai ZeZhong Software Co.,Ltd