zoukankan      html  css  js  c++  java
  • 【RobotFramework】Selenium2Library类库关键字使用说明

    Add Cookie
    Arguments:[ name | value | path=None | domain=None | secure=None | expiry=None ]
    Adds a cookie to your current session. "name" and "value" are required, "path", "domain" and "secure" are optional

    描述:添加一个 cookie 到你当前的 session 中。Name 和 value 变量为必输项,path、domain 和 secure 是选输项。

    说明:暂未使用过,待补充......

    Alert Should Be Present
    Arguments:[ text= ]
    Verifies an alert is present and dismisses it.
    If `text` is a non-empty string, then it is also verified that the message of the alert equals to `text`.
    Will fail if no alert is present. Note that following keywords will fail unless the alert is dismissed by this keyword or another like `Get Alert Message`.

    说明:校验是否有 alert 提示框出现。如果提示框信息不为空,则它将校验 alert 信息是否与 text 一致。

    例子:Alert Should Be Present | 保存成功

    Assign Id To Element
    Arguments:[ locator | id ]
    Assigns a temporary identifier to element specified by `locator`.
    This is mainly useful if the locator is complicated/slow XPath expression. Identifier expires when the page is reloaded.

    说明:分配一个临时ID给特殊元素(缺少ID或name)。

    例子:Assign Id To Element | //div[@class='textarea-clear-btn'] | ClassID01

    Call Client Method For Element
    Arguments:[ locator | jsMethodName | *args ]
    Call client method for element identified by `locator`.

    说明:暂未使用过,待补充......

    Capture Page Screenshot
    Arguments:[ filename=None ]
    Takes a screenshot of the current page and embeds it into the log.
    `filename` argument specifies the name of the file to write the screenshot into. If no `filename` is given, the screenshot is saved into file `selenium-screenshot-<counter>.png` under the directory where the Robot Framework log file is written into. The `filename` is also considered relative to the same directory, if it is not given in absolute format.
    `css` can be used to modify how the screenshot is taken. By default the bakground color is changed to avoid possible problems with background leaking when the page layout is somehow broken.

    说明:截取当前页面并将其嵌入到日志。Filename 参数指定写入日志的截图名称。如果该参数为空,那么截图名称将以”selenium-screenshot-<counter>.png”格式保存到 RF志文件所在目录下。

    例子:Capture Page Screenshot | 截图20160925001

    Checkbox Should Be Selected
    Arguments:[ locator ]
    Verifies checkbox identified by `locator` is selected/checked.
    Key attributes for checkboxes are `id` and `name`. See `introduction` for details about locating elements.

    说明:验证复选框已被选中/勾选。

    例子:Checkbox Should Be Selected | CheckBoxIDorName

    Checkbox Should Not Be Selected
    Arguments:[ locator ]
    Verifies checkbox identified by `locator` is not selected/checked.
    Key attributes for checkboxes are `id` and `name`. See `introduction` for details about locating elements.

    说明:验证复选框未被选中/勾选。

    例子:Checkbox Should Not Be Selected | CheckBoxIDorName

    Choose Cancel On Next Confirmation
    Arguments:[ ]
    Cancel will be selected the next time `Confirm Action` is used.

    说明:在含“确定/取消”的弹出框中选择“取消”,需要与关键字(Confirm Action)组合使用。

    例子:

    Choose Cancel On Next Confirmation

    Confirm Action    #选择“取消”

    Choose File
    Arguments:[ locator | file_path ]
    Inputs the `file_path` into file input field found by `identifier`.
    This keyword is most often used to input files into upload forms. The file specified with `file_path` must be available on the same host where the Selenium Server is running.

    说明:选择文件。在上传页面,直接使用该关键字。或与关键字(get file)组合使用。

    例子:

    choose file | xpath=//div[@class='pd6 dot fcb']/span/input | C:\Documents and Settings\xxx\My Documents\My Pictures\bug5.png

    choose file | get file | C:\Documents and Settings\xxx\My Documents\My Pictures\bug5.png

    Choose Ok On Next Confirmation
    Arguments:[ ]
    Undo the effect of using keywords `Choose Cancel On Next Confirmation`. Note that Selenium's overridden window.confirm() function will normally automatically return true, as if the user had manually clicked OK, so you shouldn't need to use this command unless for some reason you need to change your mind prior to the next confirmation. After any confirmation, Selenium will resume using the default behavior for future confirmations, automatically returning true (OK) unless/until you explicitly use `Choose Cancel On Next Confirmation` for each confirmation.
    Note that every time a confirmation comes up, you must consume it by using a keywords such as `Get Alert Message`, or else the following selenium operations will fail.

    说明:在含“确定/取消”的弹出框中选择“确定”。

    例子:Choose Ok On Next Confirmation

    Click Button
    Arguments:[ locator ]
    Clicks a button identified by `locator`.
    Key attributes for buttons are `id`, `name` and `value`. See `introduction` for details about locating elements.

    说明:点击按钮。需要注意点击对象必须是button,而非图片、超链接、input。

    例子:Click Button| ButtonOK

    Click Element
    Arguments:[ locator ]
    Click element identified by `locator`.
    Key attributes for arbitrary elements are `id` and `name`. See `introduction` for details about locating elements.

    说明:点击元素。可运用在任何需要点击的元素上:按钮、图片、文字、超链接等。

    例子:Click Element | xpath=//input[@value='百度一下']    #点击【百度一下】按钮

    Click Element At Coordinates
    Arguments:[ locator | xoffset | yoffset ]
    Click element identified by `locator` at x/y coordinates of the element. Cursor is moved and the center of the element and x/y coordinates are calculted from that point.
    Key attributes for arbitrary elements are `id` and `name`. See `introduction` for details about locating elements.

    说明:通过 x,y 坐标点击页面元素。

    例子:暂未使用过,待补充......

    Click Element Via Js
    Arguments:[ locator ]
    Click element identified by `locator` via javascript.

    说明:通过JavaScript定位元素。

    例子:暂未使用过,待补充......

    Click Image
    Arguments:[ locator ]
    Clicks an image found by `locator`.
    Key attributes for images are `id`, `src` and `alt`. See `introduction` for details about locating elements.

    说明:点击被定位的图片。

    例子:

    Click Image | imgLogo
    Click Image | xpath=//img[src='https://xx.xxx.xxxx.com/t0151320b1d0fc50be8.png']

    Click Link
    Arguments:[ locator ]
    Clicks a link identified by locator.
    Key attributes for links are `id`, `name`, `href` and link text. See `introduction` for details about locating elements.

    说明:点击被定位的链接。

    例子:Click Link | LinkID

    Close All Browsers
    Arguments:[ ]
    Closes all open browsers and resets the browser cache.
    After this keyword new indexes returned from `Open Browser` keyword are reset to 1.
    This keyword should be used in test or suite teardown to make sure all browsers are closed.

    说明:关闭全部打开状态的浏览器并重置缓存。执行完该关键字后,再次打开浏览器,浏览器对应 index 值从 1 开始计算。关键字必须在 test 或者 suite 的 teardown 时使用,为了确保所有浏览器已被关闭。

    Close Browser
    Arguments:[ ]
    Closes the current browser.

    说明:关闭当前浏览器。

    Close Window
    Arguments:[ ]
    Closes currently opened pop-up window.

    说明:关闭当前打开(置顶)的弹出框。

    Confirm Action
    Arguments:[ ]
    Dismisses currently shown confirmation dialog and returns it's message.
    By default, this keyword chooses 'OK' option from the dialog. If 'Cancel' needs to be chosen, keyword `Choose Cancel On Next Confirmation` must be called before the action that causes the confirmation dialog to be shown.

    说明:当前显示 confirm 对话框并返回它的 message 信息。默认情况下,该关键字选择对话框中的“确定”项。如果需要选择“取消”项,请在该关键字执行前调用“Choose Cancel On Next Confirmation”,以免对话框已关闭。

    例子1:

    Confirm Action    #单独使用时,默认点击【确定】

    例子2:

    Choose Cancel On Next Confirmation

    Confirm Action    #配合关键字Choose Cancel On Next Confirmation使用,则点击【取消】

    Current Frame Contains
    Arguments:[ text | loglevel=INFO ]
    Verifies that current frame contains `text`.
    See `Page Should Contain ` for explanation about `loglevel` argument.

    说明:验证当前frame包含的文本内容。可以查看“Page Should Contain”关于loglevel 参数的解释。

    例子:暂未使用过,待补充......

    Current Frame Should Not Contain
    Arguments:[ text | loglevel=INFO ]
    Verifies that current frame contains `text`.
    See `Page Should Contain ` for explanation about `loglevel` argument.

    说明:验证当前frame不应包含的文本。可以查看“Page Should Contain”关于loglevel 参数的解释。

    例子:暂未使用过,待补充......

    Delete All Cookies
    Arguments:[ ]
    Deletes all cookies.

    说明:删除所有Cookies。

    例子:暂未使用过,待补充......

    Delete Cookie
    Arguments:[ name ]
    Deletes cookie matching `name`.
    If the cookie is not found, nothing happens.

    说明:删除与参数 name 匹配的 cookies 信息。当未匹配到对应 name 的 cookies 信息,则不执行。

    例子:暂未使用过,待补充......

    Double Click Element
    Arguments:[ locator ]
    Double click element identified by `locator`.
    Key attributes for arbitrary elements are `id` and `name`. See `introduction` for details about locating elements.

    说明:双击元素。

    例子:Double Click Element | ElementID

    Drag And Drop
    Arguments:[ source | target ]
    Drags element identified with `source` which is a locator.
    Element can be moved on top of another element with `target` argument.
    `target` is a locator of the element where the dragged object is dropped. 

    说明:拖拽被定位 element 元素。Element 可被移动到其他目标参数上。目标为一个元素定位器,可以将对象拖拽并放下。

    例子:暂未使用,待补充......

    Drag And Drop By Offset
    Arguments:[ source | xoffset | yoffset ]
    Drags element identified with `source` which is a locator.
    Element will be moved by xoffset and yoffset. each of which is a negative or positive number specify the offset. 

    说明:将某元素从source处拖放到XY坐标指定处。

    例子:暂未使用,待补充......

    Element Should Be Disabled
    Arguments:[ locator ]
    Verifies that element identified with `locator` is disabled.
    Key attributes for arbitrary elements are `id` and `name`. See `introduction` for details about locating elements.

    说明:验证元素应被禁用(不可用)。

    例子:Element Should Be Disabled | ElementID

    Element Should Be Enabled
    Arguments:[ locator ]
    Verifies that element identified with `locator` is enabled.
    Key attributes for arbitrary elements are `id` and `name`. See `introduction` for details about locating elements.

    说明:验证元素应可用。

    例子:Element Should Be Enabled | ElementID

    Element Should Be Visible
    Arguments:[ locator | message= ]
    Verifies that the element identified by `locator` is visible.
    Herein, visible means that the element is logically visible, not optically visible in the current browser viewport. For example, an element that carries display:none is not logically visible, so using this keyword on that element would fail.
    `message` can be used to override the default error message.
    Key attributes for arbitrary elements are `id` and `name`. See `introduction` for details about locating elements.

    说明:验证元素应可见(页面有显示)。

    例子:Element Should Be Visible | ElementID | 返回自定义错误消息:对不起,该元素不可见。

    Element Should Contain
    Arguments:[ locator | expected | message= ]
    Verifies element identified by `locator` contains text `expected`.
    If you wish to assert an exact (not a substring) match on the text of the element, use `Element Text Should Be`.
    `message` can be used to override the default error message.
    Key attributes for arbitrary elements are `id` and `name`. See `introduction` for details about locating elements.

    说明:验证元素应包含的文本。

    例子:Element Should Contain | ElementID | 期望的文本内容 | 返回自定义错误消息:对不起,该元素不包含XXX文本。

    Element Should Not Be Visible
    Arguments:[ locator | message= ]
    Verifies that the element identified by `locator` is NOT visible.
    This is the opposite of `Element Should Be Visible`.
    `message` can be used to override the default error message.
    Key attributes for arbitrary elements are `id` and `name`. See `introduction` for details about locating elements.

    说明:验证元素应是不可见的。

    例子:Element Should Not Be Visible | ElementID | 返回自定义错误消息:对不起,该元素却可见。

    Element Text Should Be
    Arguments:[ locator | expected | message= ]
    Verifies element identified by `locator` exactly contains text `expected`.
    In contrast to `Element Should Contain`, this keyword does not try a substring match but an exact match on the element identified by `locator`.
    `message` can be used to override the default error message.
    Key attributes for arbitrary elements are `id` and `name`. See `introduction` for details about locating elements.

    说明:验证元素应完全包含的文本。

    例子:Element Text Should Be | ElementID | 期望的文本内容 | 返回自定义错误消息:对不起,该元素不完全包含XXX文本。

    Execute Async Javascript
    Arguments:[ *code ]
    Executes asynchronous JavaScript code.
    `code` may contain multiple lines of code but must contain a return statement (with the value to be returned) at the end.
    `code` may be divided into multiple cells in the test data. In that case, the parts are catenated together without adding spaces.
    If `code` is an absolute path to an existing file, the JavaScript to execute will be read from that file. Forward slashes work as a path separator on all operating systems.
    Note that, by default, the code will be executed in the context of the Selenium object itself, so `this` will refer to the Selenium object. Use `window` to refer to the window of your application, e.g. `window.document.getElementById('foo')`.

    说明:

    执行异步 java 脚本代码。代码可以包含多行代码但是必须包含返回信息。代码可以在测试数据中被分割为多个单元。即便如此,彼此关联的组件间不允许任意增加空间。
    如果被执行代码的路径为绝对路径,那么 javascript 将从这个绝对路径文件中读取并运行。

    例子:未使用过,待补充......

    Execute Javascript
    Arguments:[ *code ]
    Executes the given JavaScript code.
    `code` may contain multiple lines of code but must contain a return statement (with the value to be returned) at the end.
    `code` may be divided into multiple cells in the test data. In that case, the parts are catenated together without adding spaces.
    If `code` is an absolute path to an existing file, the JavaScript to execute will be read from that file. Forward slashes work as a path separator on all operating systems.
    Note that, by default, the code will be executed in the context of the Selenium object itself, so `this` will refer to the Selenium object. Use `window` to refer to the window of your application, e.g. `window.document.getElementById('foo')`. 

    说明:执行JavaScript脚本。

    例子:Execute JavaScript | window.my_js_function('arg1', 'arg2')

    Focus
    Arguments:[ locator ]
    Sets focus to element identified by `locator`.

    说明:聚焦元素。如某元素在页面上因拖动滚动条才能显示的,对该元素操作前,可使用Focus将焦点定位到该元素上,避免元素操作时找不到该元素。

    例子:Focus | ElementID

    Frame Should Contain
    Arguments:[ locator | text | loglevel=INFO ]
    Verifies frame identified by `locator` contains `text`.
    See `Page Should Contain ` for explanation about `loglevel` argument.
    Key attributes for frames are `id` and `name.` See `introduction` for details about locating elements.

    说明:验证Frame(框架)应该包含的文本。

    例子:Frame Should Contain | ElementID| 期望的文本

    Get Alert Message
    Arguments:[ ]
    Returns the text of current JavaScript alert.
    This keyword will fail if no alert is present. Note that following keywords will fail unless the alert is dismissed by this keyword or another like `Get Alert Message`.

    说明:返回警报弹出消息的文本内容,将文本返回给参数。

    例子:${ReturnMessage} | Get Alert Message

    Get All Links
    Arguments:[ ]
    Returns a list containing ids of all links found in current page.
    If a link has no id, an empty string will be in the list instead.

    说明:返回当前页包含的所有链接,将链接以列表的形式返回给参数。

    例子:${ReturnLinks} | Get All Links

    Get Cookie Value
    Arguments:[ name ]
    Returns value of cookie found with `name`.
    If no cookie is found with `name`, this keyword fails.

    说明:返回cookie的值,将值返回给参数。

    例子:${ReturnValue} | Get Cookie Value | CookieName

    Get Cookies
    Arguments:[ ]
    Returns all cookies of the current page.

    说明:返回当前页面的所有Cookies,将Cookies返回给参数。

    例子:${ReturnCookies} | Get Cookies

    Get Element Attribute
    Arguments:[ attribute_locator ]
    Return value of element attribute.
    `attribute_locator` consists of element locator followed by an @ sign and attribute name, for example "element_id@class".

    说明:返回元素的指定属性内容,将属性内容返回给参数。

    例子:${ReturnValue} | Get Element Attribute | element_id@class

  • 相关阅读:
    结束咯
    在Ubuntu上不能使用PPA下载
    月亮+大环
    piano
    花都论坛,广州花都本地生活
    LLVM的调用协议与内存对齐
    SALVIA 0.5.2优化谈
    LLVM随笔
    OS之争:永不停歇的战争(二,完结)
    OS之争:永不停歇的战争(一)
  • 原文地址:https://www.cnblogs.com/BIGMOM/p/5906714.html
Copyright © 2011-2022 走看看