51Testing软件测试论坛

标题: WatiN中所有的控件以及控件的识别方法 [打印本页]

作者: nic162534    时间: 2008-12-16 15:34
标题: WatiN中所有的控件以及控件的识别方法
在WatiN的源代码中可以看到所有的控件识别设计类都是在继承了与element相关的类
包括Element, ElementAttributeBag, ElementCollection, ElementContainer, ElementSupport, ElementTag。
首先来看Element的类可以看到它继承IAttributeBag类,在Elemental类中写到的方法有:
1. Classname: Get the name of the stylesheet class assigned to this element;得到传输给此控件默认格式类的名称。返回值为string.
2. Complete: Boolean Value, Get a value indicating whether the element is completely loaded;得到一个波尔值,查看是否此对当前控件的操作完全加载。返回值为波尔值.
3. Enabled: Get a Value indicating whether this element is enabled.得到一个波尔值来确认当前的控件是否是可用的.返回值为波尔值.
4. ID: Get the if of this element as specified in the HTML ,返回当前控件在此HTML页面中的识别ID, 返回值为string。
5.TEXT: Get the inner text of this element(or all the inner text of all the elements contained in this elment). 返回当前控件中的文本,或者是返回当前控件所包含的控件中的所有文本,返回值为string.
6.TextBefore: Returns the text displayed before this element when it’s wrapped in a Label element, otherwise it returns null. 返回当前控件前面的Label的文本内容,如果当前控件前面的控件不是Label则返回null, 返回值为string.
7. InnerHtml: Gets the inner HTML of this element. 返回当前控件的内部HTML代码。返回值不用说当然为string.
8. OuterText: Gets the outer text, 返回外部文档,返回值为string.
    Shit,这个控件我还真不知道怎么用,呵呵。查了一下解释如下:
InnerText:不包括标志,标志以内的纯文本   
  OuterText:包括标志,连标记及标志内的文本   
  InnerHtml:不包括标志,标志以内的Html内容   
  OuterHtml:包括标志,连标记及标志内的Html内容
9. TagName: Gets the tag name of this element 返回当前控件的标签。返回值为string.
10. Title: Get the title. 返回当前页面的标题。返回值为stieng.
11. NextSibling: Gets the next sibling of this element in the Dom of the HTML page.返回当前标签在此HTML页面Dom控件中的下一个兄弟控件。返回值为控件即(element)
12. PreviousSibling: Gets the previous sibling of this element in the Dom of the HTML page. 返回当前标签在此HTML页面Dom控件中的下一个兄弟控件,返回值为控件即(element)。
13. Parent: Gets the parent element of this element, If the parent type is known you can cast it to that type. 返回当前控件的父级控件,如果父级的控件类型知道,可以定义一个和父级同类型的变量控件。返回类型为控件(element).这个比较难理解,下面是举例:
      Div
        a id="watinlink" href="http://watin.sourceforge.net" /
                  a href="http://sourceforge.net/projects/watin" /
        Div
      上面的HTML所示第二个超链接没有id,如何点击它来实现超链接?这时可以使用Parent这个方法:
         首先定义一个变量Div,然后把这两个超链接所在的div赋值给这个Division变量。
  Div watinDiv = ie.Link(“watinlink”).Parent;
然后去找第二个Link, 可以把第一个Link看做是Links[0],那么第二个Link就是Link[1]
watinDiv.Links[1].Click();
14.Style: Style is the element’s style, 返回当前控件的格式。返回类型为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. 当控件的属性不存在或者或者属性属于此控件的一个子类时此方法可以使用。但是需要传递给此方法一个参数即属性名称(它应该是被IE暴露的一个空间实体),返回值为控件的属性值或者为null.
   16. ToString: Returns a string that represents the current object, or null.返回代表当前实体的值,如果没有则返回空。返回类型为string.
   17.Click: Click this element and waits till the event is completely finished(Page is loaded and ready). 点击当前控件然后等待,知道整个事件完成即:页面被完全加载。无返回值.
   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. 触发事件并立刻返回信息然后去判断需要如何执行,通常是在点击或者跳转页面还没完成时你需要其它操作。一般情况下是在当弹出对话框时使用这个方法。无返回值。
   19.Focus: Gives the input focus to this element. 聚焦在当前这个输入控件,我不是很明白这个方法。无返回值。
   20.DoubleClick: Doubleclicks this element. 双击当前的控件。无返回值。
   21.KeyDown, KeyPress, KeyUp 三个方法分别为按下键盘不放, 按一下键盘,和松开按键盘。很绕口. 这个应该是从.Net继承的。
   22. Blur: Fires the blur event on this element. 这个应该是和focus相反的方法。取消对这个控件的focus.
作者: flyingfish1026    时间: 2009-2-25 13:52
多谢多谢,请大侠们多多提供WatiN的资料哦
作者: JackieChan    时间: 2010-7-29 13:10
标题: Watin资料确实比较少
Watin资料确实比较少,目前估计使用的人也不是很多。
目前工作中的一个自动化项目我使用了Watin,下次总结后发布出来。




欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/) Powered by Discuz! X3.2