標籤:等等 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元素及元素屬性識別