1. Watin Native identification element correspondence table
2, the corresponding configuration in the source code
In Watin, a class can correspond to more than one type in the HTML, such as the TextField class can recognize tagename in HTML as input and textarea, and can be set to identify the type attribute in the input tag.
3. Attribute acquisition in HTML markup
Some common parameters are defined in the HTML element class in Watin, such as Id, Name, InnerHtml, outerHTML, Outertext, tagname, and so on, and custom properties can also be obtained through the Getattributevalue function.
Cases:
HTML content
1 <HTML>2 <Head>3 <MetaCharSet= "Utf-8">4 <title>Watin test Page</title>5 </Head>6 <Body>7 <inputID= "Text1"type= "text"value= "literal text"Customatt= "Text 1" />8 <inputID= "Text2"type= "Password"value= "Password"Customatt= "Text 2" />9 <inputID= "Text3"type= "textarea"value= "Text textarea"Customatt= "Text 3" />Ten <inputID= "Text4"type= "hidden"value= "Text hidden"Customatt= "Text 4" /> One <textareaID= "Text5"Customatt= "Text 5">Text field</textarea> A </Body> - </HTML>
C # code
1 Public Static voidTest ()2 {3 //Get IE browser4ie ie = ie. Internetexplorers (). FirstOrDefault (p = p.title! =NULL&& P.title = ="watin test Page");5StringBuilder msg =NewSystem.Text.StringBuilder ();6 stringFormatstr ="id:{0}, Type:{1}, value:{2}, customatt:{3}";7 foreach(TextField Iteminchie. Textfields)8 {9 //Get text box/field property valueTenMsg. Appendline (string. Format (Formatstr, OneItem. Gdb//Get ID Property value AItem. Getattributevalue ("type"),//get the Type property value -Item. Text,//Get display text -Item. Getattributevalue ("Customatt")//Get custom property values the )); - } - System.Windows.Forms.MessageBox.Show (Msg. ToString ()); -}
Execution results
watin-html element and element attribute recognition