首页 > 代码库 > 【RobotFramework】Selenium2Library类库关键字使用说明
【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
说明:暂未使用过,待补充......
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是否存在。
例子: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的元素。
例子: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.
说明:捕捉网页截图。可为截图命名或使用默认名(selenium-screenshot-<counter>)在指定截图保存目录下。
例子: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=http://www.mamicode.com/‘百度一下‘] #点击【百度一下】按钮
【RobotFramework】Selenium2Library类库关键字使用说明