WatiN-Html元素及元素屬性識別

來源:互聯網
上載者:User

標籤:等等   password   通過   item   .sh   分享   ati   ext3   foreach   

1、WatiN原生識別元素對應表

2、源碼中對應配置

在WatiN中一個類可以對應Html中多個類型,如,TextField類可以識別Html中TageName為input和textarea,並且可以設定input標記中type屬性進行識別。

3、Html標記中屬性擷取

在WatiN中Html元素類中定義了一些常見的參數,如:Id、Name、InnerHtml、OuterHtml、OuterText、TagName等等,也可以通過GetAttributeValue函數擷取自訂的屬性。

例:

 Html內容

 1 <html> 2 <head> 3     <meta charset="utf-8"> 4     <title>WatiN測試頁面</title> 5 </head> 6 <body> 7     <input id="text1" type="text" value="文本text" customatt="文本1" /> 8     <input id="text2" type="password" value="password" customatt="文本2" /> 9     <input id="text3" type="textarea" value="文本textarea" customatt="文本3" />10     <input id="text4" type="hidden" value="文本hidden" customatt="文本4" />11     <textarea id="text5" customatt="文本5">文本域</textarea>12 </body>13 </html>

C#代碼

 1 public static void Test() 2 { 3     //擷取IE瀏覽器 4     IE ie = IE.InternetExplorers().FirstOrDefault(p => p.Title != null && p.Title == "WatiN測試頁面"); 5     StringBuilder msg = new System.Text.StringBuilder(); 6     string formatStr = "id:{0},  type:{1},  value:{2},  customatt:{3}"; 7     foreach (TextField item in ie.TextFields) 8     { 9         //擷取文字框/域屬性值10         msg.AppendLine(string.Format(formatStr,11             item.Id,//擷取ID屬性值12             item.GetAttributeValue("type"),//擷取type屬性值13             item.Text,//擷取顯示文本14             item.GetAttributeValue("customatt")//擷取自訂屬性值15             ));16     }17     System.Windows.Forms.MessageBox.Show(msg.ToString());18 }

 

執行結果

 

WatiN-Html元素及元素屬性識別

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.