【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-
`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-
例子: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=‘百度一下‘] #点击【百度一下】按钮
1.Add Cookie [ name | value | path=None | domain=None | secure=None | expiry=None ]
给你当前的会话增加一个cookie。"name"和"value","path","domain"和"secure"是可选项。
2.Alert Should Be Present [text=]
验证Alert是否存在并且消除它。如果'text'不是空字符串,它会验证alert上的信息是否与'text'一致。
当然,如果alert不存在,测试将会失败。注意,除非通过这个关键字或者别的关键字像'Get Alert Message'消除alert,否则后面执行的关键字会失败。
3.Assign ID [ locator | id ]
分配一个临时的标识符给一个元素,首先通过'locator'来定位这个元素。
当定位该元素的Xpath表达式很复杂时,这种方法非常有用。此外,当页面重新载入时,这个标识符就到期了。
4.Capture Page Screenshot [ filename=None ]
在当前页面上截屏,并把它放在日志里。
'filename'参数指定了一个元素的名称并把截屏写入。如果没有提供'filename',截屏将会被保存在'selenium-screenshot-
5.Checkbox Should Be Selected [ locator ]
验证'locator'标识的checkbox是否被选定。
6.Checkbox Should Not Be Selected [ locator ]
验证'locator'标识的checkbox没有被选定。
7.Choose Cancel On Next Confirmation [ ]
下次'Confirm Action'被使用时,撤销将会被选定。
8.Choose File [ locator | file_path ]
将'file_path'写入被标识的文件写入区域。
这个关键字被经常使用去将文件写入到上传表格中。由'file_path'指定的文件必须存在于Selenium Server 运行的主机上。
9.Choose Ok On Next Confirmation [ ]
取消使用'Choose Cancel on Next Confirmation'这个关键字的影响。注意,Selenium的重写window.confirm()函数通常会自动返回true,就好似用户手动的点击OK,所以你应该不需要这个命令,除非你需要改变你的next confirmation的首选项因为某些原因。在任一confirmation之后,Selenium将会为未来的confirmatons恢复使用默认值,自动的返回true(OK)除非你明确的对每一个confirmation使用'Choose Cancel On Next Confirmation'。
还要注意每次一个confirmation开始时,你必须使用'Get Alert Mseeage'等类似的关键字,不然selenium接下来的操作将会失败。
10.Click Button [ locator ]
点击被'locator'标识的按钮。
11.Click Element [ ]
点击被'locator'标识的元素。
12.Click Element At Coordinates [ ]
点击被'locator'标识的元素,以该元素的x/y坐标为基准。鼠标移动到该元素的中心,x/y坐标就从那一点被计算出来。
13.Click Image [ ]
点击被'locator'标识的图片。
14.Click Link [ ]
点击被'locator'标识的链接。
15.Close All Browsers [ ]
关掉所有打开的浏览器,并且重置这些浏览器的缓存。
这个关键字被执行之后,从'Open Browser'关键字返回的新的索引被重置为1。
这个关键字应该被用在test或者suite的teardown中,以确保所有浏览器被关闭。
16.Close Browser [ ]
关闭当前运行的浏览器。
17.Close Window [ ]
关闭当前弹出的窗口。
18.Confirm Action [ ]
关闭当前显示的会话并返回它的信息。
这个关键字会默认选择会话中的'OK'。如果需要选择‘Cancel’,关键字'Choose Cancel On Next Confirmation'必须在引起确认会话被显示的行为之前被调用。
例子:
Click Button | Send | # Shows a confirmation dialog |
${message}= | Confirm Action | # Chooses Ok |
Should Be Equal | ${message} | Are your sure? |
Choose Cancel On Next Confirmation | ||
Click Button | Send | # Shows a confirmation dialog |
Confirm Action | # Chooses Cancel |
19.Current Frame Contains [text|loglevel=INFO]
核实当前frame是否包含'text'。
20.Current Frame Should Not Contain [text|loglevel=INFO]
核实当前frame是否包含'text'。
21.Delete All Cookies []
删除所有cookies。
22.Delete Cookie [name]
删除匹配'name'的cookie。如果这个cookie没有被发现,什么事都不会发生。
23.Double Click Element [locator]
双击被'locator'标识的元素。
24.Drag And Drop [source|target]
拖拽被'source‘ (实际是一个'locator')定位的元素。
元素可被移动到其它目标元素之上。
'target'是一个元素定位器,指定了拖拽住的元素松开的位置。
25.Drop And Drop By Offset [source|xoffset|yoffset]
拖拽被'source‘ (实际是一个'locator')定位的元素。
元素将会被移动到坐标xoffset和yoffset指定的位置。坐标可以是正数也可是负数。
26.Element Should Be Disabled [locator]
验证被'locator'指定的元素是否可用。
27.Element Should Be Enabled [locator]
验证被'locator'指定的元素是否可用。
28.Element Should Be Visible []
验证被'locator'指定的元素是否可见。
这里,可见指的是逻辑可见,而不是在当前浏览器窗口上的视觉可见。举个例子,一个元素呈现为none,那么该元素就是逻辑上不可见的,所以在这个元素上使用此关键字将会失败。
29.Element Should Contain [loactor|expected|message=]
验证被'locator'定位的元素是否包含文本'expected'。
如果你想要在元素的文本里断言一个精确的匹配而不是一个子串,使用关键字'Element Text Should Be'。
'message'可被用于覆盖默认的错误信息。
30.Element Should Not Be Visible [locator|message=]
验证被'locator'定位的元素是不可见的。
是关键字'Element Should Be Visible'的反义。
'message'可被用于覆盖默认的错误信息。
31.Element Text Should Be [locator|expected|message=]
验证被'locator'定位的元素是否精确的包含文本'expected'。
与'Element Should Contain'形成对比,这个关键字不是在被'locator'标识的元素上尝试子串匹配,而是精确匹配。
32.Execute Async Javascript [*code]
执行异步JS代码。
'code'可能含有很多行代码,但是最后必须包含一个返回状态(即要有返回值)。
'code'也许在测试数据中被分成很多单元。即便如此,彼此关联的部分不允许增加任何空间。
如果'code'是一个指向一个存在的文件的完整的路径,JS将从这个文件中读取并执行。分隔号'/'用于所有操作系统的路径分隔。
注意,默认地,代码将会在Selenium对象自己的环境中执行。所以,'this'将会适用于the Selenium 对象。使用'window'去适用于你的应用的窗口。例如,'window.document.getElementById('foo')'.
33.Execute Javascript [*code]
执行提供的js代码。
同关键字32。
34.Focus [locator]
设置被'locator'定位的元素为焦点。
35.Frame Should Contain [locator|text|loglevel=INFO]
验证被'locator'定位的'frame'是否包含'text'。
36.Get Alert Message []
返回当前js alert里的内容。
如果当前没有alert,这个关键字将会失败。注意,接下来的关键字将会失败除非alert通过这个关键字或者'Get Alert Message'被消除。
37.Get All Links []
返回一个列表,该列表包含当前页面所有链接的id。
如果一个链接没有id,这个列表将含有一个空的字符串。
38.Get Cookie Value [name]
返回名称为'name'的cookie的值。
如果没有cookie叫'name',这个关键字失败。
39.Get cookies []
返回当前页面的所有cookie。
40.Get Element Attribute [attribute_locator]
返回元素属性的值。
属性定位器'attribute_locator'由标识@和属性名称组成,如"element_id@class"
41.Get Horizontal Position [locator]
返回被'locator'定位的元素的水平位置。
位置作为正数类型被返回到页面左侧的像素位置。如果没有找到匹配的元素,将会失败。
42.Get List Items [locator]
从已被'locator'定位select list中返回值。
Select list 关键字工作在每个列表和组合框中。select list的关键属性是'id'和'name'。
43.Get Location []
返回当前的位置。
44.Get Matching Xpath Count [xpath]
返回匹配'xpath'的若干元素。
如果你想断言若干匹配的元素,使用'Xpath Should Match X Times'.
45.Get Selected List Label [locator]
从被'locator'定位的select list中返回可见的选项元素的标签。
Select list 关键字工作在每个列表和组合框中。select list的关键属性是'id'和'name'。
46.Get Selected List Labels [locator]
从被'locator'定位的select list中返回可见的选项元素的标签(作为一个列表)。
如果没有选项将会失败。
47.Get Selected List Value [locator]
从被'locator'标识的的select list中返回选中的元素的值。
返回值被选中的元素的'value'属性读取。
Select list 关键字工作在每个列表和组合框中。select list的关键属性是'id'和'name'。
48.Get Selected List Values [locator]
从被'locator'标识的的select list中返回选中的元素的值(作为一个列表)。
返回值被选中的元素的'value'属性读取。
Select list 关键字工作在每个列表和组合框中。select list的关键属性是'id'和'name'。
49.Get Selenium Implicit Wait []
获取Selenium隐式等待时间。
50.Get Selenium Speed []
获取每一条执行Selenium命令时的延迟等待时间。
51.Get Selenium Timeout []
在短时间内获取timeout,被不同的关键字使用。
52.Get Source []
从当前页面或框架返回整个html源。