*** Settings *** Documentation Simple example using SeleniumLibrary. Library SeleniumLibrary 官网地址 https://pypi.org/project/robotframework-seleniumlibrary/#extending-seleniumlibrary *** Variables *** ${LOGIN URL} http://localhost:7272 --定义URL 地址 ${BROWSER} Chrome --选择驱动的浏览器 *** Test Cases *** 打开浏览器登陆 例子 Valid Login Open Browser To Login Page ---打开浏览器 Input Username demo ----填写姓名 Input Password mode ----填写密码 Submit Credentials ----提交表单 Welcome Page Should Be Open [Teardown] Close Browser ---关闭浏览器 *** Keywords *** 分解登陆 Open Browser To Login Page Open Browser ${LOGIN URL} ${BROWSER} Title Should Be Login Page Input Username 分解输入用户 [Arguments] ${username} Input Text username_field ${username} Input Password 分解输入密码 [Arguments] ${password} Input Text password_field ${password} Submit Credentials 点击提交按钮 Click Button login_button Welcome Page Should Be Open ---断言 验证 Title Should Be Welcome Page
SeleniumLibrary中须要与网页上的元素交互的全部关键字都采用一般命名的参数来locator
指定如何查找元素。大多数状况下,定位器使用下面描述的定位器语法做为字符串给出,但也能够使用WebElements。css
SeleniumLibrary支持基于不一样策略查找元素,例如元素id,XPath表达式或CSS选择器。可使用前缀显式指定策略,也能够隐式策略。html
默认状况下,定位器被视为使用关键字特定的默认定位器策略。全部关键字都支持基于id
和name
属性查找元素,但某些关键字支持其上下文中有意义的其余属性或其余值。例如,Click Link支持href
属性和连接文本以及正常id
和添加name
python
Examples:jquery
Click Element | example | # Match based on id or name . 匹配基于id 或name |
Click Link | example | # Match also based on link text and href .匹配也基于连接文本和href |
Click Button | example | # Match based on id , name or value . 匹配基于id ,name 或value |
若是定位器意外地以识别为显式定位器策略或隐式XPath策略的前缀启动,则可使用显式default
前缀来启用默认策略android
Examples:git
Click Element | name:foo | # Find element with name foo . 查找名称元素foo |
Click Element | default:name:foo | # Use default strategy with value name:foo . 使用带有值的默认策略name:foo |
Click Element | //foo | # Find element using XPath //foo . 使用XPath查找元素//foo |
Click Element | default: //foo | # Use default strategy with value //foo . 使用带有值的默认策略//foo |
使用语法strategy:value
或使用前缀指定显式定位器策略strategy=value
。前一种语法是首选,由于后者与Robot Framework的命名参数语法相同,而且可能致使问题。围绕分离空间被忽略,所以id:foo
,id: foo
和id : foo
都是等效的。github
Locator strategies that are supported by default are listed in the table below. In addition to them, it is possible to register custom locators.web
Strategy | Match based on | Example |
---|---|---|
id | Element id . |
id:example |
name | name attribute. |
name:example |
identifier | Either id or name . |
identifier:example |
class | Element class . |
class:example |
tag | Tag name. | tag:div |
xpath | XPath expression. | xpath://div[@id="example"] |
css | CSS selector. | css:div#example |
dom | DOM expression. | dom:document.images[5] |
link | Exact text a link has. | link:The example |
partial link | Partial link text. | partial link:he ex |
sizzle | Sizzle selector provided by jQuery. | sizzle:div.example |
jquery | Same as the above. | jquery:div.example |
default | Keyword specific default behavior. | default:example |
有关默认策略如何工做的详细信息,请参阅下面的“ 默认定位器策略”部分。default
仅当定位符值自己意外地匹配某些显式策略时,才须要使用显式前缀。chrome
不一样的定位策略有不一样的优缺点。使用IDS,明确地喜欢id:foo
或使用默认的定位策略只是想foo
,若是条件可能,由于语法很简单,由一个id定位元素是快的浏览器。若是元素没有id或id不稳定,则须要使用其余解决方案。若是一个元素都有一个惟一的标签名称或类别,使用tag
,class
或css
策略同样tag:h1
,class:example
或者css:h1.example
是常常一个简单的解决方案。在更复杂的状况下,使用XPath表达式一般是最好的方法。它们很是强大,但缺点是它们也会变得复杂。express
Examples:
Click Element | id:foo | # Element with id 'foo'. |
Click Element | css:div#foo h1 | # h1 element under div with id 'foo'. |
Click Element | xpath: //div[@id="foo"]//h1 | # Same as the above using XPath, not CSS. |
Click Element | xpath: //*[contains(text(), "example")] | # Element containing text 'example'. |
注意:
strategy:value
只有SeleniumLibrary 3.0及更高版本支持该语法。sizzle
策略或其别名jquery
要求被测系统包含jQuery库。xpath
,css
并sizzle/jquery
战略。若是定位器以//
或开头(//
,则定位器被视为XPath表达式。换句话说,使用//div
等同于使用显式xpath://div
。
例子:
Click Element | //div[@id="foo"]//h1 |
Click Element | (//div)[2] |
The support for the (//
prefix is new in SeleniumLibrary 3.0.
除了将定位器指定为字符串以外,还可使用Selenium的WebElement对象。这须要首先获取WebElement
${elem} = | Get WebElement | id:example |
Click Element | ${elem} |
若是须要比经过默认定位器提供的查找更复杂的查找,则能够建立自定义查找策略。使用自定义定位器是一个两部分过程。首先,建立一个返回应该对其执行操做的WebElement的关键字:
Custom Locator Strategy | [Arguments] | ${browser} | ${strategy} | ${tag} | ${constraints} |
${element}= | Execute Javascript | return window.document.getElementById('${criteria}'); | |||
[Return] | ${element} |
此关键字是对id
定位器基本功能的从新实现,其中${browser}
是对WebDriver实例的引用,而且${strategy}
是定位器策略的名称。要使用此定位器,必须首先使用“ 添加位置策略”关键字进行注册:
Add Location Strategy | custom | Custom Locator Strategy 自定义定位器策略 |
The first argument of Add Location Strategy specifies the name of the strategy and it must be unique. After registering the strategy, the usage is the same as with other locators:
Click Element | custom:example |
See the Add Location Strategy keyword for more details.
本节讨论如何等待元素在网页上显示以及下降执行速度的不一样方法。它还解释了设置各类超时,等待和延迟时可使用的时间格式。
SeleniumLibrary包含各类关键字,timeout
这些关键字具备可选参数,用于指定这些关键字应等待某些事件或操做的时间。这些关键字包括例如Wait ...
与警报相关的关键字和关键字。
这些关键字使用的默认超时能够经过使用Set Selenium Timeout关键字或导入库timeout
时的参数进行全局设置。请参阅如下时间格式以获取支持的超时语
隐式等待指定Selenium在搜索元素时等待的最长时间。可使用Set Selenium Implicit Wait关键字或导入库implicit_wait
时的参数进行设置。有关此功能的更多信息,请参阅Selenium文档。
请参阅如下时间格式以获取支持的语
All timeouts and waits can be given as numbers considered seconds (e.g. 0.5
or 42
) or in Robot Framework's time syntax (e.g. 1.5 seconds
or 1 min 30 s
). For more information about the time syntax see the Robot Framework User Guide.
SeleniumLibrary有一个方便的功能,它能够自动执行关键字,若是任何本身的关键字失败。默认状况下,它使用Capture Page Screenshot关键字,但可使用“ 注册关键字运行失败”关键字或导入库run_on_failure
时的参数进行更改。可使用任何导入的库或资源文件中的任何关键字。
能够经过使用特殊值NOTHING
或任何被视为false的函数(请参阅布尔参数)来禁用运行失败功能NONE
。
Some keywords accept arguments that are handled as Boolean values true or false. If such an argument is given as a string, it is considered false if it is either empty or case-insensitively equal to false
, no
or none
. Other strings are considered true regardless their value, and other argument types are tested using same rules as in Python.
True examples:
Set Screenshot Directory | ${RESULTS} | persist=True | # Strings are generally true. |
Set Screenshot Directory | ${RESULTS} | persist=yes | # Same as the above. |
Set Screenshot Directory | ${RESULTS} | persist=${TRUE} | # Python True is true. |
Set Screenshot Directory | ${RESULTS} | persist=${42} | # Numbers other than 0 are true. |
False examples:
Set Screenshot Directory | ${RESULTS} | persist=False | # String false is false. |
Set Screenshot Directory | ${RESULTS} | persist=no | # Also string no is false. |
Set Screenshot Directory | ${RESULTS} | persist=NONE | # String NONE is false. |
Set Screenshot Directory | ${RESULTS} | persist=${EMPTY} | # Empty string is false. |
Set Screenshot Directory | ${RESULTS} | persist=${FALSE} | # Python False is false. |
Set Screenshot Directory | ${RESULTS} | persist=${NONE} | # Python None is false. |
Arguments | Documentation |
---|---|
timeout=5.0, implicit_wait=0.0, run_on_failure=Capture Page Screenshot,screenshot_root_directory=None | SeleniumLibrary can be imported with several optional arguments.
|
Add Cookie · Add Location Strategy · Alert Should Be Present · Alert Should Not Be Present · Assign Id To Element · Capture Page Screenshot · Checkbox Should Be Selected · Checkbox Should Not Be Selected ·Choose Cancel On Next Confirmation · Choose File · Choose Ok On Next Confirmation · Clear Element Text · Click Button · Click Element · Click Element At Coordinates · Click Image · Click Link · Close All Browsers · Close Browser ·Close Window · Confirm Action · Create Webdriver · Current Frame Contains · Current Frame Should Contain · Current Frame Should Not Contain · Delete All Cookies · Delete Cookie · Dismiss Alert · Double Click Element ·Drag And Drop · Drag And Drop By Offset · Element Should Be Disabled · Element Should Be Enabled · Element Should Be Focused · Element Should Be Visible · Element Should Contain · Element Should Not Be Visible ·Element Should Not Contain · Element Text Should Be · Element Text Should Not Be · Execute Async Javascript · Execute Javascript · Focus · Frame Should Contain · Get Alert Message · Get All Links · Get Cookie · Get Cookie Value ·Get Cookies · Get Element Attribute · Get Element Count · Get Element Size · Get Horizontal Position · Get List Items · Get Location · Get Locations · Get Matching Xpath Count · Get Selected List Label · Get Selected List Labels ·Get Selected List Value · Get Selected List Values · Get Selenium Implicit Wait · Get Selenium Speed · Get Selenium Timeout · Get Source · Get Table Cell · Get Text · Get Title · Get Value · Get Vertical Position · Get WebElement ·Get WebElements · Get Window Handles · Get Window Identifiers · Get Window Names · Get Window Position · Get Window Size · Get Window Titles · Go Back · Go To · Handle Alert · Input Password · Input Text · Input Text Into Alert· Input Text Into Prompt · List Selection Should Be · List Should Have No Selections · List Windows · Location Should Be · Location Should Contain · Locator Should Match X Times · Log Location · Log Source · Log Title ·Maximize Browser Window · Mouse Down · Mouse Down On Image · Mouse Down On Link · Mouse Out · Mouse Over · Mouse Up · Open Browser · Open Context Menu · Page Should Contain · Page Should Contain Button ·Page Should Contain Checkbox · Page Should Contain Element · Page Should Contain Image · Page Should Contain Link · Page Should Contain List · Page Should Contain Radio Button · Page Should Contain Textfield ·Page Should Not Contain · Page Should Not Contain Button · Page Should Not Contain Checkbox · Page Should Not Contain Element · Page Should Not Contain Image · Page Should Not Contain Link · Page Should Not Contain List ·Page Should Not Contain Radio Button · Page Should Not Contain Textfield · Press Key · Radio Button Should Be Set To · Radio Button Should Not Be Selected · Register Keyword To Run On Failure · Reload Page ·Remove Location Strategy · Select All From List · Select Checkbox · Select Frame · Select From List · Select From List By Index · Select From List By Label · Select From List By Value · Select Radio Button · Select Window ·Set Browser Implicit Wait · Set Focus To Element · Set Screenshot Directory · Set Selenium Implicit Wait · Set Selenium Speed · Set Selenium Timeout · Set Window Position · Set Window Size · Simulate · Simulate Event · Submit Form ·Switch Browser · Table Cell Should Contain · Table Column Should Contain · Table Footer Should Contain · Table Header Should Contain · Table Row Should Contain · Table Should Contain · Textarea Should Contain ·Textarea Value Should Be · Textfield Should Contain · Textfield Value Should Be · Title Should Be · Unselect All From List · Unselect Checkbox · Unselect Frame · Unselect From List · Unselect From List By Index ·Unselect From List By Label · Unselect From List By Value · Wait For Condition · Wait Until Element Contains · Wait Until Element Does Not Contain · Wait Until Element Is Enabled · Wait Until Element Is Not Visible ·Wait Until Element Is Visible · Wait Until Page Contains · Wait Until Page Contains Element · Wait Until Page Does Not Contain · Wait Until Page Does Not Contain Element · Xpath Should Match X Times
添加曲奇 · 添加位置策略 · 警报应该存在 · 警报应该不存在 · 指定ID来元 · 捕获页面截图 · 复选框应选择 · 复选框,则不该选择 · 选择取消在接下来确认 · 选择文件 · 选择肯定(OK)下一个确认 · 清除元素文本 · 单击按钮 · 单击元素 · 单击坐标时的元素 ·单击图像 · 单击连接 · 关闭全部浏览器 · 关闭浏览器 · 关闭窗口 · 确认操做 · 建立Webdriver · 当前帧包含 · 当前帧应包含 · 当前帧不该包含 · 删除全部Cookie · 删除Cookie · 关闭警报 · 双击元素 · 拖放 · 拖放拖放 · 元素应禁用 · 元素应启用 · 元素应聚焦 ·元素应该是可见的 · 元素应该包含 · 元素不该该是可见的 · 元素不该该包含 · 元素文本应该是 · 元素文本不该该 · 执行异步Javascript · 执行Javascript · 焦点 · 框架应该包含 · 获取警报消息 · 获取全部连接 · 获取Cookie · 获取Cookie值 · 获取Cookie ·获取元素属性 · 获取元素计数 · 获取元素大小 · 获取水平位置 · 获取列表项 · 获取位置 · 获取位置 · 获取匹配的XPath计数 · 获取选定列表标签 · 获取选定列表标签 · 获取所选列表值 · 获取选定的值列表 · 让Selenium隐等待 · 让Selenium速度 ·让Selenium超时 · 获取源 · 获取表格单元格 · 获取文本 · 拿不到冠军 · 获取价值 · 获取垂直位置 · 获取Web元素 · 获取Web元素 · 获取窗口句柄 · 获取窗口标识符 · 获取窗口名称 · 获取窗口位置 · 获取窗口大小 · 获取窗口标题 · 返回 · 转到 · 处理警报 ·输入密码 · 输入文本 · 输入文本到警报 · 输入文本到提示 · 列表选择应该 · 列表应该没有选择 · 列出Windows · 位置应该 · 位置应该包含 · 定位器应该匹配X次 · 日志位置 · 日志源 · 日志标题 · 最大化浏览器窗口 · 鼠标按下 · 鼠标按下图像 · 鼠标按下连接 ·鼠标移动 · 鼠标移动 · 鼠标移动 · 打开浏览器 · 打开上下文菜单 · 页面应包含 · 页面应包含按钮 · 页面应包含复选框 · 页面应包含元素 · 页面应包含图像 · 页面应包含连接 · 页面应包含列表 · 页面应包含单选按钮 · 页面应包含文本字段 · 页面不该包含 ·页面不该包含按钮 · 页面不该包含复选框 · 页面不该包含元素 · 页面不该包含图像 · 页面不该包含连接 · 页面不该包含列表 · 页面不该包含单选按钮 · 页面不该包含文本字段 · 按键 · 单选按钮应设置为 · 单选按钮,则不该选择 · 注册关键字上运行故障 ·刷新页面 · 删除定位策略 · 选择所有从列表 · 选择复选框 · 选择第一帧 · 从列表中选择 · 从列表中选择按索引 · 从列表中选择按标签 · 选择从按价值列出 · 选择单选按钮 · 选择窗口 · 设置浏览器隐式等待 · 将焦点设置为元素 · 设置屏幕截图目录 ·设置Selenium隐式等待 · 设置Selenium速度 · 设置Selenium超时 · 设置窗口位置 · 设置窗口大小 · 模拟 · 模拟事件 · 提交表单 · 切换浏览器 · 表单元格应包含 · 表列应该包含 · 表格底部应该包含 · 表头应该包含 · 表行应该包含 · 表应包含 ·多行文本应该包含 · textarea的值应该是 ? 文本框应该包含 · 文本字段的值应该 · 标题应该是 · 取消所有从列表 · 取消选择复选框 · 取消选择框 · 取消选择从列表 · 取消选择从列表按索引 · 取消选择从列表按标签 · 取消选择从列表按值 · 等待条件 ·等到元素包含 · 等到元素不包含 · 等到元素被启用 · 等到元素不可见 · 等到元素可见 · 等到页面包含 · 等到页面包含元素 · 等到页面不包含 · 等待直到页面不包含元素 · Xpath应匹配X次
Keyword | Arguments | Documentation | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Add Cookie 添加Cookie | name, value, path=None,domain=None, secure=None,expiry=None | Adds a cookie to your current session.
Example:
Prior to SeleniumLibrary 3.0 setting expiry did not work. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Add Location Strategy 添加位置策略 | strategy_name, strategy_keyword,persist=False | 添加自定义位置策略。 有关如何建立和使用自定义策略的信息,请参阅自定义定位器。删除位置策略可用于删除已注册的策略。 默认状况下,在离开当前做用域后会自动删除位置策略。设置 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Alert Should Be Present 警报应该存在 | text=, action=ACCEPT, timeout=None | 验证是否存在警报,而且默认状况下接受警报。 若是没有警报则失败。若是
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Alert Should Not Be Present 警报不该该存在 | action=ACCEPT, timeout=0 |
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Assign Id To Element | locator, id | 将临时分配 若是定位器是复杂的和/或缓慢的XPath表达式而且须要屡次,则这很是有用。标识符在从新加载页面时到期。 Example:
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Capture Page Screenshot 捕获页面截图 | filename=selenium-screenshot-{index}.png | 获取当前页面的屏幕截图并将其嵌入到日志文件中。
从SeleniumLibrary 1.8开始,若是 返回建立的屏幕截图文件的绝对路径 Examples:
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Checkbox Should Be Selected 应选中复选框 | locator |
See the Locating elements section for details about the locator syntax. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Checkbox Should Not Be Selected不该选中复选框 | locator |
See the Locating elements section for details about the locator syntax.. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Choose Cancel On Next Confirmation | 已过期。请直接使用Handle Alert。 In versions prior to SeleniumLibrary 3.0, the alert handling approach needed to be set separately before using the Confirm Action keyword. New Handle Alert keyword accepts the action how to handle the alert as a normal argument and should be used instead. |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Choose File 选择文件 | locator, file_path | 输入 此关键字最经常使用于将文件输入上载表单。指定的文件
Example:
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Choose Ok On Next Confirmation | 已过期。请直接使用Handle Alert In versions prior to SeleniumLibrary 3.0, the alert handling approach needed to be set separately before using the Confirm Action keyword. New Handle Alert keyword accepts the action how to handle the alert as a normal argument and should be used instead. |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Clear Element Text 清除元素文本 | locator | 清除标识的文本输入元素的值 See the Locating elements section for details about the locator syntax. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Click Button 单击按钮 | locator | 点击按钮标识 See the Locating elements section for details about the locator syntax. When using the default locator strategy, buttons are searched using |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Click Element 单击元素 | locator | 单击标识的元素 See the Locating elements section for details about the locator syntax. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Click Element At Coordinates 单击坐标处的元素 | locator, xoffset, yoffset |
See the Locating elements section for details about the locator syntax. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Click Image 单击图像 | locator | 单击标识的图像 See the Locating elements section for details about the locator syntax. When using the default locator strategy, images are searched using |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Click Link 单击连接 | locator | 单击标识的连接 See the Locating elements section for details about the locator syntax. When using the default locator strategy, links are searched using |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Close All Browsers 关闭全部浏览器 | 关闭全部打开的浏览器并重置浏览器缓存。 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. |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Close Browser 关闭浏览器 | 关闭当前浏览器。 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Close Window 关闭窗口 | 关闭当前打开的弹出窗口。 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Confirm Action 确认行动 | 已过期。请改用Handle Alert。 By default accepts an alert, but this behavior can be altered with Choose Cancel On Next Confirmation and Choose Ok On Next Confirmation keywords. New Handle Alert keyword accepts the action how to handle the alert as a normal argument and should be used instead. |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Create Webdriver 建立Webdriver | driver_name, alias=None, kwargs={},**init_kwargs | Creates an instance of Selenium WebDriver. Like Open Browser, but allows passing arguments to the created WebDriver instance directly. This keyword should only be used if functionality provided by Open Browser is not adequate.
The initialized WebDriver can be configured either with a Python dictionary Examples:
Returns the index of this browser instance which can be used later to switch back to it. Index starts from 1 and is reset back to it when Close All Browsers keyword is used. See Switch Browser for an example. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Current Frame Contains | text, loglevel=INFO | 已过期. Use Current Frame Should Contain instead. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Current Frame Should Contain 当前框架应包含 | text, loglevel=INFO | 验证当前帧是否包含 See Page Should Contain for explanation about the Prior to SeleniumLibrary 3.0 this keyword was named Current Frame Contains. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Current Frame Should Not Contain 当前框架不该包含 | text, loglevel=INFO | 验证当前帧是否包含 See Page Should Contain for explanation about the |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Delete All Cookies删除全部Cookie | 删除全部cookie。 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Delete Cookie 删除Cookie | name | 删除cookie匹配 If the cookie is not found, nothing happens. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Dismiss Alert | accept=True | 已过期. Use Handle Alert instead. Contrary to its name, this keyword accepts the alert by default (i.e. presses Handle Alert has better support for controlling should the alert be accepted, dismissed, or left open. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Double Click Element 双击元素 | locator | 双击标识的元素 See the Locating elements section for details about the locator syntax. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Drag And Drop 拖放 | locator, target | drags元素由 该
Example:
拖放CSS:DIV元素#CSS:div.target
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Drag And Drop By Offset经过偏移拖放 | locator, xoffset, yoffset | 拖拽元素 元素将被移动, Example:
经过偏移拖放myElem50-35#向右移动myElem 50px,向下移动35px |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Element Should Be Disabled 元素应该被禁用 | locator | 验证标识的元素 This keyword considers also elements that are read-only to be disabled. See the Locating elements section for details about the locator syntax. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Element Should Be Enabled 应该启用元素 | locator | 验证 This keyword considers also elements that are read-only to be disabled. See the Locating elements section for details about the locator syntax. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Element Should Be Focused 元素应该集中 | locator | 验证标识的元素 See the Locating elements section for details about the locator syntax. New in SeleniumLibrary 3.0. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Element Should Be Visible 元素应该是可见的 | locator, message=None | 验证标识的元素 这里,visible表示该元素在逻辑上可见,在当前浏览器视口中不是光学可见的。例如,携带的元素在 该 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Element Should Contain 元素应该包含 | locator, expected, message=None,ignore_case=False |
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Element Should Not Be Visible | locator, message=None | 验证标识的元素 Passes if element does not exists. See Element Should Be Visible for more information about visibility and supported arguments. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Element Should Not Contain 元素不该该包含 | locator, expected, message=None,ignore_case=False | 验证该元素 该 该
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Element Text Should Be 元素文本应该是 | locator, expected, message=None,ignore_case=False | 验证该元素是否 该 该
若是须要子字符串匹配,则使用元素应包含。 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Element Text Should Not Be 元素文本不该该 | locator, not_expected, message=None,ignore_case=False | 验证该元素 该 该 SeleniumLibrary 3.1.1中的新功能 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Execute Async Javascript 执行异步Javascript | *code | 执行异步JavaScript代码。 与Execute Javascript相似,不一样之处在于使用此关键字执行的脚本必须经过调用提供的回调明确表示它们已完成。此回调始终做为最后一个参数注入到执行的函数中。 脚本必须在脚本超时内完成,不然此关键字将失败。有关详细信息,请参阅超时部分。 Examples:
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Execute Javascript 执行Javascript | *code | 执行给定的JavaScript代码。
若是 JavaScript在当前选定的框架或窗口的上下文中执行,做为匿名函数的主体。用 此关键字返回执行的JavaScript代码返回的任何内容。返回值将转换为适当的Python类型。 Examples:
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Focus | locator | 已过期. Use Set Focus To Element instead. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Frame Should Contain 框架应该包含 | locator, text, loglevel=INFO | 验证由 See Page Should Contain for explanation about the |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Get Alert Message 获取提醒消息 | dismiss=True | 过期. Use Handle Alert instead. Returns the message the alert has. Dismisses the alert by default (i.e. presses Handle Alert has better support for controlling should the alert be accepted, dismissed, or left open. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Get All Links 获取全部连接 | 返回包含当前页面中找到的全部连接的ID的列表。 若是连接没有id,则列表中将出现一个空字符串 |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Get Cookie | name | Returns information of cookie with If no cookie is found with
See the WebDriver specification for details about the cookie information. Notice that Example:
New in SeleniumLibrary 3.0. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Get Cookie Value | name | Deprecated. Use Get Cookie instead. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Get Cookies | Returns all cookies of the current page. The cookie information is returned as a single string in format |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Get Element Attribute | locator, attribute=None | Returns value of See the Locating elements section for details about the locator syntax. Example:
Passing attribute name as part of the |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Get Element Count | locator | Returns number of elements matching If you wish to assert the number of matching elements, use Page Should Contain Element with Example:
New in SeleniumLibrary 3.0. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Get Element Size | locator | Returns width and height of element identified by See the Locating elements section for details about the locator syntax. Both width and height are returned as integers. Example:
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Get Horizontal Position | locator | Returns horizontal position of element identified by See the Locating elements section for details about the locator syntax. The position is returned in pixels off the left side of the page, as an integer. See also Get Vertical Position. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Get List Items | locator, values=False | Returns all labels or values of selection list See the Locating elements section for details about the locator syntax. Returns visible labels by default, but values can be returned by setting the Example:
Support to return values is new in SeleniumLibrary 3.0. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Get Location | Returns the current browser URL. |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Get Locations | Returns and logs URLs of all known browser windows. |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Get Matching Xpath Count | xpath, return_str=True | Deprecated. Use Get Element Count instead. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Get Selected List Label | locator | Returns label of selected option from selection list If there are multiple selected options, label of the first option is returned. See the Locating elements section for details about the locator syntax. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Get Selected List Labels | locator | Returns labels of selected options from selection list Starting from SeleniumLibrary 3.0, returns an empty list if there are no selections. In earlier versions this caused an error. See the Locating elements section for details about the locator syntax. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Get Selected List Value | locator | Returns value of selected option from selection list If there are multiple selected options, value of the first option is returned. See the Locating elements section for details about the locator syntax. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Get Selected List Values | locator | Returns values of selected options from selection list Starting from SeleniumLibrary 3.0, returns an empty list if there are no selections. In earlier versions this caused an error. See the Locating elements section for details about the locator syntax. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Get Selenium Implicit Wait | Gets the implicit wait value used by Selenium. The value is returned as a human readable string like See the Implicit wait section above for more information. |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Get Selenium Speed | Gets the delay that is waited after each Selenium command. The value is returned as a human readable string like See the Selenium Speed section above for more information. |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Get Selenium Timeout | Gets the timeout that is used by various keywords. The value is returned as a human readable string like See the Timeout section above for more information. |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Get Source | Returns the entire HTML source of the current page or frame. |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Get Table Cell | locator, row, column, loglevel=INFO | Returns contents of table cell. The table is located using the Both row and column indexes start from 1, and header and footer rows are included in the count. It is possible to refer to rows and columns from the end by using negative indexes so that -1 is the last row/column, -2 is the second last, and so on. All See Page Should Contain for explanation about the |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Get Text | locator | Returns the text value of element identified by See the Locating elements section for details about the locator syntax. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Get Title | Returns the title of current page. |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Get Value | locator | Returns the value attribute of element identified by See the Locating elements section for details about the locator syntax. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Get Vertical Position | locator | Returns vertical position of element identified by See the Locating elements section for details about the locator syntax. The position is returned in pixels off the top of the page, as an integer. See also Get Horizontal Position. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Get WebElement | locator | Returns the first WebElement matching the given See the Locating elements section for details about the locator syntax. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Get WebElements | locator | Returns list of WebElement objects matching the See the Locating elements section for details about the locator syntax. Starting from SeleniumLibrary 3.0, the keyword returns an empty list if there are no matching elements. In previous releases the keyword failed in this case. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Get Window Handles | Return all current window handles as a list. Can be used as a list of windows to exclude with Select Window. Prior to SeleniumLibrary 3.0, this keyword was named List Windows. |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Get Window Identifiers | Returns and logs id attributes of all known browser windows. |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Get Window Names | Returns and logs names of all known browser windows. |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Get Window Position | Returns current window position. Position is relative to the top left corner of the screen. Returned values are integers. See also Set Window Position. Example:
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Get Window Size | Returns current window width and height as integers. See also Set Window Size. Example:
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Get Window Titles | Returns and logs titles of all known browser windows. |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Go Back | Simulates the user clicking the back button on their browser. |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Go To | url | Navigates the active browser instance to the provided |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Handle Alert | action=ACCEPT, timeout=None | Handles the current alert and returns its message. By default the alert is accepted, but this can be controlled with the
The Examples:
New in SeleniumLibrary 3.0. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Input Password | locator, password | Types the given password into text field identified by See the Locating elements section for details about the locator syntax. Difference compared to Input Text is that this keyword does not log the given password on the INFO level. Notice that if you use the keyword like
the password is shown as a normal keyword argument. A way to avoid that is using variables like
Notice also that SeleniumLibrary logs all the communication with browser drivers using the DEBUG level, and the actual password can be seen there. Additionally Robot Framework logs all arguments using the TRACE level. Tests must thus not be executed using level below INFO if password should not be logged in any format. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Input Text | locator, text | Types the given Use Input Password if you do not want the given See the Locating elements section for details about the locator syntax. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Input Text Into Alert | text, action=ACCEPT, timeout=None | Types the given The alert is accepted by default, but that behavior can be controlled by using the
New in SeleniumLibrary 3.0. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Input Text Into Prompt | text | Deprecated. Use Input Text Into Alert instead. Types the given |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
List Selection Should Be | locator, *expected | Verifies selection list It is possible to give expected options both as visible labels and as values. Starting from SeleniumLibrary 3.0, mixing labels and values is not possible. Order of the selected options is not validated. If no expected options are given, validates that the list has no selections. A more explicit alternative is using List Should Have No Selections. See the Locating elements section for details about the locator syntax. Examples:
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
List Should Have No Selections | locator | Verifies selection list See the Locating elements section for details about the locator syntax. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
List Windows | Deprecated. Use Get Window Handles instead. |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Location Should Be | url | Verifies that current URL is exactly |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Location Should Contain | expected | Verifies that current URL contains |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Locator Should Match X Times | locator, x, message=None,loglevel=INFO | Deprecated, use Page Should Contain Element with |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Log Location | Logs and returns the current URL. |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Log Source | loglevel=INFO | Logs and returns the HTML source of the current page or frame. The |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Log Title | Logs and returns the title of current page. |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Maximize Browser Window | Maximizes current browser window. |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Mouse Down | locator | Simulates pressing the left mouse button on the element See the Locating elements section for details about the locator syntax. The element is pressed without releasing the mouse button. See also the more specific keywords Mouse Down On Image and Mouse Down On Link. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Mouse Down On Image | locator | Simulates a mouse down event on an image identified by See the Locating elements section for details about the locator syntax. When using the default locator strategy, images are searched using |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Mouse Down On Link | locator | Simulates a mouse down event on a link identified by See the Locating elements section for details about the locator syntax. When using the default locator strategy, links are searched using |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Mouse Out | locator | Simulates moving mouse away from the element See the Locating elements section for details about the locator syntax. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Mouse Over | locator | Simulates hovering mouse over the element See the Locating elements section for details about the locator syntax. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Mouse Up | locator | Simulates releasing the left mouse button on the element See the Locating elements section for details about the locator syntax. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Open Browser | url, browser=firefox, alias=None,remote_url=False,desired_capabilities=None,ff_profile_dir=None | Opens a new browser instance to the given The
To be able to actually use one of these browsers, you need to have a matching Selenium browser driver available. See the project documentation for more details. Headless Firefox and Headless Chrome are new additions in SeleniumLibrary 3.1.0 and require Selenium 3.8.0 or newer. Optional Optional Optional Optional Examples:
If the provided configuration options are not enough, it is possible to use Create Webdriver to customize browser initialization even more. Applying |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Open Context Menu | locator | Opens context menu on element identified by |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Page Should Contain | text, loglevel=INFO | Verifies that current page contains If this keyword fails, it automatically logs the page source using the log level specified with the optional |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Page Should Contain Button | locator, message=None, loglevel=INFO | Verifies button See Page Should Contain Element for explanation about See the Locating elements section for details about the locator syntax. When using the default locator strategy, buttons are searched using |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Page Should Contain Checkbox | locator, message=None, loglevel=INFO | Verifies checkbox See Page Should Contain Element for explanation about See the Locating elements section for details about the locator syntax. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Page Should Contain Element | locator, message=None, loglevel=INFO,limit=None | Verifies that element See the Locating elements section for details about the locator syntax. The The See Page Should Contain for explanation about the Examples assumes that locator matches to two elements.
The |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Page Should Contain Image | locator, message=None, loglevel=INFO | Verifies image identified by See the Locating elements section for details about the locator syntax. When using the default locator strategy, images are searched using See Page Should Contain Element for explanation about |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Page Should Contain Link | locator, message=None, loglevel=INFO | Verifies link identified by See the Locating elements section for details about the locator syntax. When using the default locator strategy, links are searched using See Page Should Contain Element for explanation about |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Page Should Contain List | locator, message=None, loglevel=INFO | Verifies selection list See Page Should Contain Element for explanation about See the Locating elements section for details about the locator syntax. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Page Should Contain Radio Button | locator, message=None, loglevel=INFO | Verifies radio button See Page Should Contain Element for explanation about See the Locating elements section for details about the locator syntax. When using the default locator strategy, radio buttons are searched using |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Page Should Contain Textfield | locator, message=None, loglevel=INFO | Verifies text field See Page Should Contain Element for explanation about See the Locating elements section for details about the locator syntax. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Page Should Not Contain | text, loglevel=INFO | Verifies the current page does not contain See Page Should Contain for explanation about the |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Page Should Not Contain Button | locator, message=None, loglevel=INFO | Verifies button See Page Should Contain Element for explanation about See the Locating elements section for details about the locator syntax. When using the default locator strategy, buttons are searched using |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Page Should Not Contain Checkbox | locator, message=None, loglevel=INFO | Verifies checkbox See Page Should Contain Element for explanation about See the Locating elements section for details about the locator syntax. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Page Should Not Contain Element | locator, message=None, loglevel=INFO | Verifies that element See the Locating elements section for details about the locator syntax. See Page Should Contain for explanation about |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Page Should Not Contain Image | locator, message=None, loglevel=INFO | Verifies image identified by See the Locating elements section for details about the locator syntax. When using the default locator strategy, images are searched using See Page Should Contain Element for explanation about |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Page Should Not Contain Link | locator, message=None, loglevel=INFO | Verifies link identified by See the Locating elements section for details about the locator syntax. When using the default locator strategy, links are searched using See Page Should Contain Element for explanation about |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Page Should Not Contain List | locator, message=None, loglevel=INFO | Verifies selection list See Page Should Contain Element for explanation about See the Locating elements section for details about the locator syntax. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Page Should Not Contain Radio Button | locator, message=None, loglevel=INFO | Verifies radio button See Page Should Contain Element for explanation about See the Locating elements section for details about the locator syntax. When using the default locator strategy, radio buttons are searched using |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Page Should Not Contain Textfield | locator, message=None, loglevel=INFO | Verifies text field See Page Should Contain Element for explanation about See the Locating elements section for details about the locator syntax. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Press Key | locator, key | Simulates user pressing key on element identified by See the Locating elements section for details about the locator syntax.
Examples:
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Radio Button Should Be Set To | group_name, value | Verifies radio button group
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Radio Button Should Not Be Selected | group_name | Verifies radio button group
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Register Keyword To Run On Failure | keyword | Sets the keyword to execute when a SeleniumLibrary keyword fails.
The initial keyword to use is set when importing the library, and the keyword that is used by default is Capture Page Screenshot. Taking a screenshot when something failed is a very useful feature, but notice that it can slow down the execution. It is possible to use string This keyword returns the name of the previously registered failure keyword or Python Example:
Changes in SeleniumLibrary 3.0:
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Reload Page | Simulates user reloading page. |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Remove Location Strategy | strategy_name | Removes a previously added custom location strategy. See Custom locators for information how to create and use custom strategies. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Select All From List | locator | Selects all options from multi-selection list See the Locating elements section for details about the locator syntax. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Select Checkbox | locator | Selects checkbox identified by Does nothing if checkbox is already selected. See the Locating elements section for details about the locator syntax. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Select Frame | locator | Sets frame identified by See the Locating elements section for details about the locator syntax. Works both with frames and iframes. Use Unselect Frame to cancel the frame selection and return to the main frame. Example:
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Select From List | locator, *options | Deprecated. Use Select From List By Label/Value/Index instead. This keyword selects options based on labels or values, which makes it very complicated and slow. It has been deprecated in SeleniumLibrary 3.0, and dedicated keywords Select From List By Label, Select From List By Value and Select From List By Index should be used instead. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Select From List By Index | locator, *indexes | Selects options from selection list Indexes of list options start from 0. If more than one option is given for a single-selection list, the last value will be selected. With multi-selection lists all specified options are selected, but possible old selections are not cleared. See the Locating elements section for details about the locator syntax. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Select From List By Label | locator, *labels | Selects options from selection list If more than one option is given for a single-selection list, the last value will be selected. With multi-selection lists all specified options are selected, but possible old selections are not cleared. See the Locating elements section for details about the locator syntax. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Select From List By Value | locator, *values | Selects options from selection list If more than one option is given for a single-selection list, the last value will be selected. With multi-selection lists all specified options are selected, but possible old selections are not cleared. See the Locating elements section for details about the locator syntax. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Select Radio Button | group_name, value | Sets radio button group The radio button to be selected is located by two arguments:
Examples:
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Select Window | locator=MAIN | Selects browser window matching If the window is found, all subsequent commands use the selected window, until this keyword is used again. If the window is not found, this keyword fails. The previous window handle is returned, and can be used to return back to it later. Notice that in this context window means a pop-up window opened when doing something on an existing window. It is not possible to select windows opened with Open Browser, Switch Browser must be used instead. Notice also that alerts should be handled with Handle Alert or other alert related keywords. The
Example:
NOTE:
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Set Browser Implicit Wait | value | Sets the implicit wait value used by Selenium. Same as Set Selenium Implicit Wait but only affects the current browser. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Set Focus To Element | locator | Sets focus to element identified by See the Locating elements section for details about the locator syntax. Prior to SeleniumLibrary 3.0 this keyword was named Focus. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Set Screenshot Directory | path, persist=DEPRECATED | Sets the directory for captured screenshots.
The previous value is returned and can be used to restore the original value later if needed. Deprecating |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Set Selenium Implicit Wait | value | Sets the implicit wait value used by Selenium. The value can be given as a number that is considered to be seconds or as a human readable string like This keyword sets the implicit wait for all opened browsers. Use Set Browser Implicit Wait to set it only to the current browser. See the Implicit wait section above for more information. Example:
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Set Selenium Speed | value | Sets the delay that is waited after each Selenium command. The value can be given as a number that is considered to be seconds or as a human readable string like See the Selenium Speed section above for more information. Example:
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Set Selenium Timeout | value | Sets the timeout that is used by various keywords. The value can be given as a number that is considered to be seconds or as a human readable string like See the Timeout section above for more information. Example:
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Set Window Position | x, y | Sets window position using The position is relative to the top left corner of the screen, but some browsers exclude possible task bar set by the operating system from the calculation. The actual position may thus be different with different browsers. Values can be given using strings containing numbers or by using actual numbers. See also Get Window Position. Example:
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Set Window Size | width, height | Sets current windows size to given Values can be given using strings containing numbers or by using actual numbers. See also Get Window Size. Browsers have a limit how small they can be set. Trying to set them smaller will cause the actual size to be bigger than the requested size. Example:
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Simulate | locator, event | Deprecated. Use Simulate Event instead. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Simulate Event | locator, event | Simulates This keyword is useful if element has See the Locating elements section for details about the locator syntax. Prior to SeleniumLibrary 3.0 this keyword was named Simulate. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Submit Form | locator=None | Submits a form identified by If See the Locating elements section for details about the locator syntax. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Switch Browser | index_or_alias | Switches between active browsers using Indices are returned by the Open Browser keyword and aliases can be given to it explicitly. Indices start from 1. Example:
Above example expects that there was no other open browsers when opening the first one because it used index
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Table Cell Should Contain | locator, row, column, expected,loglevel=INFO | Verifies table cell contains text See Get Table Cell that this keyword uses internally for explanation about accepted arguments. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Table Column Should Contain | locator, column, expected,loglevel=INFO | Verifies table column contains text The table is located using the Column indexes start from 1. It is possible to refer to columns from the end by using negative indexes so that -1 is the last column, -2 is the second last, and so on. If a table contains cells that span multiple columns, those merged cells count as a single column. See Page Should Contain Element for explanation about the |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Table Footer Should Contain | locator, expected, loglevel=INFO | Verifies table footer contains text Any The table is located using the See Page Should Contain Element for explanation about the |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Table Header Should Contain | locator, expected, loglevel=INFO | Verifies table header contains text Any The table is located using the See Page Should Contain Element for explanation about the |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Table Row Should Contain | locator, row, expected, loglevel=INFO | Verifies that table row contains text The table is located using the Row indexes start from 1. It is possible to refer to rows from the end by using negative indexes so that -1 is the last row, -2 is the second last, and so on. If a table contains cells that span multiple rows, a match only occurs for the uppermost row of those merged cells. See Page Should Contain Element for explanation about the |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Table Should Contain | locator, expected, loglevel=INFO | Verifies table contains text The table is located using the See Page Should Contain Element for explanation about the |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Textarea Should Contain | locator, expected, message=None | Verifies text area
See the Locating elements section for details about the locator syntax. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Textarea Value Should Be | locator, expected, message=None | Verifies text area
See the Locating elements section for details about the locator syntax. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Textfield Should Contain | locator, expected, message=None | Verifies text field
See the Locating elements section for details about the locator syntax. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Textfield Value Should Be | locator, expected, message=None | Verifies text field
See the Locating elements section for details about the locator syntax. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Title Should Be | title, message=None | Verifies that current page title equals The
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Unselect All From List | locator | Unselects all options from multi-selection list See the Locating elements section for details about the locator syntax. New in SeleniumLibrary 3.0. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Unselect Checkbox | locator | Removes selection of checkbox identified by Does nothing if the checkbox is not selected. See the Locating elements section for details about the locator syntax. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Unselect Frame | Sets the main frame as the current frame. In practice cancels the previous Select Frame call. |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Unselect From List | locator, *items | Deprecated. Use Unselect From List By Label/Value/Index instead. This keyword unselects options based on labels or values, which makes it very complicated and slow. It has been deprecated in SeleniumLibrary 3.0, and dedicated keywords Unselect From List By Label, Unselect From List By Value and Unselect From List By Index should be used instead. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Unselect From List By Index | locator, *indexes | Unselects options from selection list Indexes of list options start from 0. This keyword works only with multi-selection lists. See the Locating elements section for details about the locator syntax. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Unselect From List By Label | locator, *labels | Unselects options from selection list This keyword works only with multi-selection lists. See the Locating elements section for details about the locator syntax. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Unselect From List By Value | locator, *values | Unselects options from selection list This keyword works only with multi-selection lists. See the Locating elements section for details about the locator syntax. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Wait For Condition | condition, timeout=None, error=None | Waits until The condition can be arbitrary JavaScript expression but it must return a value to be evaluated. See Execute JavaScript for information about accessing content on pages. Fails if the timeout expires before the condition becomes true. See the Timeouts section for more information about using timeouts and their default value.
Examples:
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Wait Until Element Contains | locator, text, timeout=None,error=None | Waits until element Fails if
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Wait Until Element Does Not Contain | locator, text, timeout=None,error=None | Waits until element Fails if
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Wait Until Element Is Enabled | locator, timeout=None, error=None | Waits until element Element is considered enabled if it is not disabled nor read-only. Fails if
Considering read-only elements to be disabled is a new feature in SeleniumLibrary 3.0. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Wait Until Element Is Not Visible | locator, timeout=None, error=None | Waits until element Fails if
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Wait Until Element Is Visible | locator, timeout=None, error=None | Waits until element Fails if
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Wait Until Page Contains | text, timeout=None, error=None | Waits until Fails if
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Wait Until Page Contains Element | locator, timeout=None, error=None | Waits until element Fails if
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Wait Until Page Does Not Contain | text, timeout=None, error=None | Waits until Fails if
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Wait Until Page Does Not Contain Element | locator, timeout=None, error=None | Waits until element Fails if
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Xpath Should Match X Times | xpath, x, message=None,loglevel=INFO | Deprecated, use Page Should Contain Element with |
关键词 | 参数 | 文档 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
添加Cookie | name, value, path = None, domain = None, secure = None, expiry = None | 在当前会话中添加cookie。
例:
在SeleniumLibrary 3.0设置到期以前不起做用。 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
添加位置策略 | strategy_name, strategy_keyword, persist = False | 添加自定义位置策略。 有关如何建立和使用自定义策略的信息,请参阅自定义定位器。删除位置策略可用于删除已注册的策略。 默认状况下,在离开当前做用域后会自动删除位置策略。设置 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
警报应该存在 | text =, action = ACCEPT, timeout = None | 验证是否存在警报,而且默认状况下接受警报。 若是没有警报则失败。若是
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
警报不该该存在 | action = ACCEPT, timeout = 0 | 验证没有警报。 若是警报确实存在,则
SeleniumLibrary 3.0中的新功能。 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
将Id分配给元素 | 定位器, 身份 | 将临时分配 若是定位器是复杂的和/或缓慢的XPath表达式而且须要屡次,则这很是有用。标识符在从新加载页面时到期。 例:
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
捕获页面截图 | 文件名=硒 - screenshot- {索引} .PNG | 获取当前页面的屏幕截图并将其嵌入到日志文件中。
从SeleniumLibrary 1.8开始,若是 返回建立的屏幕截图文件的绝对路径。 例子:
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
应选中复选框 | 定位器 |
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
不该选中复选框 | 定位器 |
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
选择取消下次确认 | 已过期。请直接使用Handle Alert。 在SeleniumLibrary 3.0以前的版本中,须要在使用Confirm Action关键字以前单独设置警报处理方法。New Handle Alert关键字接受如何将警报做为普通参数处理的操做,应该使用它。 |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
选择文件 | locator, file_path | 输入 此关键字最经常使用于将文件输入上载表单。指定的文件 例:
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
选择Ok On Next Confirmation | 已过期。请直接使用Handle Alert。 在SeleniumLibrary 3.0以前的版本中,须要在使用Confirm Action关键字以前单独设置警报处理方法。New Handle Alert关键字接受如何将警报做为普通参数处理的操做,应该使用它。 |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
清除元素文本 | 定位器 | 清除标识的文本输入元素的值 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
单击按钮 | 定位器 | 点击按钮标识 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
单击元素 | 定位器 | 单击标识的元素 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
单击坐标处的元素 | 定位器, xoffset, yoffset | 点击元素 移动光标,从该点计算元素的中心和x / y坐标。 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
单击图像 | 定位器 | 单击标识的图像 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
单击连接 | 定位器 | 单击标识的连接 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
关闭全部浏览器 | 关闭全部打开的浏览器并重置浏览器缓存。 在此关键字以后,从Open Browser关键字返回的新索引将重置为1。 此关键字应在测试或套件拆解中使用,以确保全部浏览器都已关闭。 |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
关闭浏览器 | 关闭当前浏览器。 |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
关闭窗口 | 关闭当前打开的弹出窗口。 |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
确认行动 | 已过期。请改用Handle Alert。 默认状况下,接受警报,但能够经过选择取消确认下一个确认并选择肯定下一个确认关键字来更改此行为。New Handle Alert关键字接受如何将警报做为普通参数处理的操做,应该使用它。 |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
建立Webdriver | driver_name, alias = None, kwargs = {}, ** init_kwargs | 建立Selenium WebDriver的实例。 与Open Browser相似,但容许直接将参数传递给建立的WebDriver实例。仅当Open Browser提供的功能不足时,才应使用此关键字。
初始化的WebDriver可使用Python字典 例子:
返回此浏览器实例的索引,稍后可使用该索引切换回它。索引从1开始,并在使用Close All Browsers关键字时重置为它。有关示例,请参阅Switch Browser。 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
当前帧包含 | text, loglevel = INFO | 已过期。使用当前帧应该包含。 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
当前框架应包含 | text, loglevel = INFO | 验证当前帧是否包含 有关参数的说明,请参见页面应包含 在SeleniumLibrary 3.0以前,此关键字被命名为Current Frame Contains。 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
当前框架不该包含 | text, loglevel = INFO | 验证当前帧是否包含 有关参数的说明,请参见页面应包含 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
删除全部Cookie | 删除全部cookie。 |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
删除Cookie | 名称 | 删除cookie匹配 若是找不到cookie,则没有任何反应。 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
解雇警报 | 接受=真 | 已过期。请改用Handle Alert。 与其名称相反,此关键字默认接受警报(即按下 若是警报被接受,解雇或保持开放,则处理警报能够更好地支持控制。 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
双击元素 | 定位器 | 双击标识的元素 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
拖放 | 定位器, 目标 | drags元素由 该 例:
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
经过偏移拖放 | 定位器, xoffset, yoffset | 拖拽元素 元素将被移动, 例:
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
元素应该被禁用 | 定位器 | 验证标识的元素 此关键字还会考虑禁用只读的元素。 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
应该启用元素 | 定位器 | 验证 此关键字还会考虑禁用只读的元素。 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
元素应该集中 | 定位器 | 验证标识的元素 SeleniumLibrary 3.0中的新功能。 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
元素应该是可见的 | locator, message =无 | 验证标识的元素 这里,visible表示该元素在逻辑上可见,在当前浏览器视口中不是光学可见的。例如,携带的元素在 该 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
元素应该包含 | locator, expected, message = None, ignore_case = False | 验证该元素是否 该 该
若是要匹配确切的文本而不是子字符串,则应使用元素文本。 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
元素不该该是可见的 | locator, message =无 | 验证标识的元素 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
元素不该该包含 | locator, expected, message = None, ignore_case = False | 验证该元素 该 该
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
元素文本应该是 | locator, expected, message = None, ignore_case = False | 验证该元素是否 该 该
若是须要子字符串匹配,则使用元素应包含。 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
元素文本不该该 | locator, not_expected, message = None, ignore_case = False | 验证该元素 该 该 SeleniumLibrary 3.1.1中的新功能 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
执行异步Javascript | *码 | 执行异步JavaScript代码。 与Execute Javascript相似,不一样之处在于使用此关键字执行的脚本必须经过调用提供的回调明确表示它们已完成。此回调始终做为最后一个参数注入到执行的函数中。 脚本必须在脚本超时内完成,不然此关键字将失败。有关详细信息,请参阅超时部分。 例子:
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
执行Javascript | *码 | 执行给定的JavaScript代码。
若是 JavaScript在当前选定的框架或窗口的上下文中执行,做为匿名函数的主体。用 此关键字返回执行的JavaScript代码返回的任何内容。返回值将转换为适当的Python类型。 例子:
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
焦点 | 定位器 | 已过期。请改成使用Set Focus To Element。 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
框架应该包含 | locator, text, loglevel = INFO | 验证由 有关参数的说明,请参见页面应包含 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
获取提醒消息 | 解雇=真 | 已过期。请改用Handle Alert。 返回警报的消息。默认状况下解除警报(即按下 若是警报被接受,解雇或保持开放,则处理警报能够更好地支持控制。 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
获取全部连接 | 返回包含当前页面中找到的全部连接的ID的列表。 若是连接没有id,则列表中将出现一个空字符串。 |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
获取Cookie | 名称 |
若是未找到cookie
有关cookie信息的详细信息,请参阅WebDriver规范。请注意,它 例:
SeleniumLibrary 3.0中的新功能。 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
获取Cookie值 | 名称 | 已过期。请改用Get Cookie。 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
获取Cookies | 返回当前页面的全部cookie。 cookie信息以格式的单个字符串形式返回 |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
获取元素属性 | locator, attribute = None | 返回 例:
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
获取元素计数 | 定位器 | 返回匹配的元素数 若是要声明匹配元素的数量,请使用Page should Contain Element with 例:
SeleniumLibrary 3.0中的新功能。 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
获取元素大小 | 定位器 | 返回由标识的元素的宽度和高度 宽度和高度都以整数形式返回。 例:
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
得到横向位置 | 定位器 | 返回由标识的元素的水平位置 位置以页面左侧的像素为单位返回,为整数。 另请参阅获取垂直位置。 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
获取列表项 | locator, values = False | 返回选择列表的全部标签或值 默认状况下返回可见标签,但能够经过将 例:
支持返回值是SeleniumLibrary 3.0中的新功能。 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
获取位置 | 返回当前的浏览器URL。 |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
获取地点 | 返回并记录全部已知浏览器窗口的URL。 |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
获取匹配的Xpath计数 | xpath, return_str = True | 已过期。请改用“ 获取元素计数”。 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
获取选定的列表标签 | 定位器 | 从选择列表返回所选选项的标签 若是有多个选定选项,则返回第一个选项的标签。 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
获取选定列表标签 | 定位器 | 从选择列表返回所选选项的标签 从SeleniumLibrary 3.0开始,若是没有选择,则返回一个空列表。在早期版本中,这会致使错误。 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
获取选定的列表值 | 定位器 | 从选择列表返回所选选项的值 若是有多个选定选项,则返回第一个选项的值。 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
获取选定的列表值 | 定位器 | 从选择列表返回所选选项的值 从SeleniumLibrary 3.0开始,若是没有选择,则返回一个空列表。在早期版本中,这会致使错误。 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
获取Selenium Implicit Wait | 获取Selenium使用的隐式等待值。 该值做为人类可读的字符串返回 有关详细信息,请参阅上面的隐式等待部分。 |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
得到Selenium Speed | 获取每一个Selenium命令后等待的延迟。 该值做为人类可读的字符串返回 有关详细信息,请参阅上面的Selenium Speed部分。 |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
获取Selenium Timeout | 获取各类关键字使用的超时。 该值做为人类可读的字符串返回 有关详细信息,请参阅上面的超时部分。 |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
获取来源 | 返回当前页面或框架的整个HTML源。 |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
获取表格单元格 | 定位器, 行, 列, loglevel = INFO | 返回表格单元格的内容。 使用 行索引和列索引都从1开始,页眉和页脚行包含在计数中。能够经过使用负索引从末尾引用行和列,以便-1是最后一行/列,-2是最后一行,依此类推。 全部 有关参数的说明,请参见页面应包含 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
获取文字 | 定位器 | 返回由标识的元素的文本值 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
得到标题 | 返回当前页面的标题。 |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
得到价值 | 定位器 | 返回由标识的元素的value属性 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
得到垂直位置 | 定位器 | 返回由标识的元素的垂直位置 位置以页面顶部的像素为单位返回,做为整数。 另请参见获取水平位置。 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
获取WebElement | 定位器 | 返回与给定匹配的第一个WebElement |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
获取WebElements | 定位器 | 返回与之匹配的WebElement对象列表 从SeleniumLibrary 3.0开始,若是没有匹配的元素,关键字将返回一个空列表。在之前的版本中,关键字在这种状况下失败。 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
获取窗口句柄 | 将全部当前窗口句柄做为列表返回。 能够用做要使用选择窗口排除的窗口列表。 在SeleniumLibrary 3.0以前,此关键字被命名为List Windows。 |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
获取窗口标识符 | 返回并记录全部已知浏览器窗口的id属性。 |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
获取窗口名称 | 返回并记录全部已知浏览器窗口的名称。 |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
获取窗口位置 | 返回当前窗口位置。 位置相对于屏幕的左上角。返回值是整数。另请参见设置窗口位置。 例:
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
获取窗口大小 | 以整数形式返回当前窗口宽度和高度。 另请参见设置窗口大小。 例:
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
获取窗口标题 | 返回并记录全部已知浏览器窗口的标题。 |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
回去 | 模拟用户单击其浏览器上的后退按钮。 |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
去 | 网址 | 将活动的浏览器实例导航到提供的实例 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
处理警报 | action = ACCEPT, timeout = None | 处理当前警报并返回其消息。 默认状况下,接受警报,但可使用
该 例子:
SeleniumLibrary 3.0中的新功能。 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
输入密码 | 定位器, 密码 | 将给定密码键入标识的文本字段 与输入文本相比的差别是此关键字不会在INFO级别上记录给定的密码。请注意,若是您使用关键字like
密码显示为普通关键字参数。避免这种状况的一种方法是使用像
另请注意,SeleniumLibrary使用DEBUG级别记录与浏览器驱动程序的全部通讯,而且能够在那里看到实际密码。此外,Robot Framework使用TRACE级别记录全部参数。所以,若是不以任何格式记录密码,则必须使用低于INFO的级别执行测试。 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
输入文本 | 定位器, 文本 | 将给定的 若是您不但愿记录给定,请使用输入密码 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
将文本输入警报 | text, action = ACCEPT, timeout = None | 将给定类型 默认状况下接受警报,但可使用
SeleniumLibrary 3.0中的新功能。 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
将文本输入到提示中 | 文本 | 已过期。请改用输入文本到警报。 将给定类型 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
列表选择应该是 | 定位器, *预期 | 验证选择列表 能够将预期选项做为可见标签和值给出。从SeleniumLibrary 3.0开始,没法混合标签和值。未验证所选选项的顺序。 若是未给出预期选项,则验证列表没有选择。更明确的替代方案是使用列表应该没有选择。 例子:
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
列表应该没有选择 | 定位器 | 验证选择列表 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
列出Windows | 已过期。请改用“ 获取窗口句柄”。 |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
位置应该是 | 网址 | 验证当前URL是否彻底正确 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
位置应该包含 | 预期 | 验证当前URL是否包含 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
定位器应该匹配X次 | locator, x, message = None, loglevel = INFO | 不推荐使用,请使用Page should Contain Element with |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
记录位置 | 记录并返回当前URL。 |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
日志源 | 记录等级= INFO | 记录并返回当前页面或框架的HTML源。 该 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
日志标题 | 记录并返回当前页面的标题。 |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
最大化浏览器窗口 | 最大化当前浏览器窗口。 |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
鼠标向下 | 定位器 | 模拟按下元素上的鼠标左键 按下元素而不释放鼠标按钮。 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
鼠标在图像上 | 定位器 | 在由标识的图像上模拟鼠标按下事件 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
鼠标按下连接 | 定位器 | 在由标识的连接上模拟鼠标按下事件 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
鼠标移出 | 定位器 | 模拟将鼠标移离元素 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
鼠标移到 | 定位器 | 模拟将鼠标悬停在元素上 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
鼠标向上 | 定位器 | 模拟释放元素上的鼠标左键 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
打开浏览器 | url, browser = firefox, alias = None, remote_url = False,desired_capabilities = None, ff_profile_dir = None | 打开给定的新浏览器实例 该
为了可以实际使用这些浏览器之一,您须要提供匹配的Selenium浏览器驱动程序。有关详细信息,请参阅项目文档。Headless Firefox和Headless Chrome是SeleniumLibrary 3.1.0中的新增功能,须要Selenium 3.8.0或更新版本。 可选 可选 可选 可选的 例子:
若是提供的配置选项不够,则可使用Create Webdriver进一步自定义浏览器初始化。
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
打开上下文菜单 | 定位器 | 在标识的元素上打开上下文菜单 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
页面应该包含 | text, loglevel = INFO | 验证当前页面是否包含 若是此关键字失败,它将使用使用optional |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
页面应包含按钮 | locator, message = None, loglevel = INFO |
有关和参数的说明,请参见页面应包含元素。 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
页面应包含复选框 | locator, message = None, loglevel = INFO |
有关和参数的说明,请参见页面应包含元素。 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
页面应包含元素 | locator, message = None, loglevel = INFO, limit = None | 验证 该 该 有关参数的说明,请参见页面应包含 示例假定定位器与两个元素匹配。
这个 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
页面应包含图像 | locator, message = None, loglevel = INFO | 验证 有关定位器语法的详细信息,请参阅定位元素部分。当使用默认的定位策略,图像是使用搜索 有关和参数的说明,请参见页面应包含元素。 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
页面应包含连接 | locator, message = None, loglevel = INFO | 验证 有关定位器语法的详细信息,请参阅定位元素部分。当使用默认的定位策略,连接使用搜索 有关和参数的说明,请参见页面应包含元素。 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
页面应包含列表 | locator, message = None, loglevel = INFO | 验证 有关和参数的说明,请参见页面应包含元素。 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
页面应包含单选按钮 | locator, message = None, loglevel = INFO |
有关和参数的说明,请参见页面应包含元素。 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
页面应包含文本字段 | locator, message = None, loglevel = INFO | 验证 有关和参数的说明,请参见页面应包含元素。 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
页面不该该包含 | text, loglevel = INFO | 验证当前页面不包含 有关参数的说明,请参见页面应包含 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
页面不该包含按钮 | locator, message = None, loglevel = INFO |
有关和参数的说明,请参见页面应包含元素。 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
页面不该包含复选框 | locator, message = None, loglevel = INFO |
有关和参数的说明,请参见页面应包含元素。 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
页面不该包含元素 | locator, message = None, loglevel = INFO | 验证 有关和参数的说明,请参见页面应包含。 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
页面不该包含图像 | locator, message = None, loglevel = INFO | 验证 有关定位器语法的详细信息,请参阅定位元素部分。当使用默认的定位策略,图像是使用搜索 有关和参数的说明,请参见页面应包含元素。 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
页面不该包含连接 | locator, message = None, loglevel = INFO | 验证 有关定位器语法的详细信息,请参阅定位元素部分。当使用默认的定位策略,连接使用搜索 有关和参数的说明,请参见页面应包含元素。 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
页面不该包含列表 | locator, message = None, loglevel = INFO | 验证 有关和参数的说明,请参见页面应包含元素。 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
页面不该包含单选按钮 | locator, message = None, loglevel = INFO |
有关和参数的说明,请参见页面应包含元素。 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
页面不该包含文本字段 | locator, message = None, loglevel = INFO | 验证 有关和参数的说明,请参见页面应包含元素。 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
按键 | 定位器, 关键 | 模拟用户按下标识的元素上的键
例子:
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
单选按钮应设置为 | group_name, value | 验证单选按钮组
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
不该选择单选按钮 | 团队名字 | 验证单选按钮组
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
注册关键字以在失败时运行 | 关键词 | 设置SeleniumLibrary关键字失败时要执行的关键字。
导入库时设置要使用的初始关键字,默认状况下使用的关键字是Capture Page Screenshot。在出现故障时拍摄屏幕截图是一个很是有用的功能,但请注意它能够减慢执行速度。 可使用字符串
例:
SeleniumLibrary 3.0的变化:
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
从新加载页面 | 模拟用户从新加载页面。 |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
删除位置策略 | STRATEGY_NAME | 删除之前添加的自定义位置策略。 有关如何建立和使用自定义策略的信息,请参阅自定义定位器。 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
从列表中选择所有 | 定位器 | 从多选列表中选择全部选项 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
选择复选框 | 定位器 | 选择标识的复选框 若是已选中复选框则不执行任何操做 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
选择框架 | 定位器 | 设置由 适用于框架和iframe。使用取消选择框取消帧选择并返回主框架。 例:
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
从列表中选择 | 定位器, *选项 | 已过期。使用从标签/值/索引按列表选择。 此关键字根据标签或值选择选项,这使得它很是复杂和缓慢。它已经在SeleniumLibrary 3.0被弃用,而专用的关键字从列表中选择按标签,从列表中选择按值,并从列表中选择按索引应改成使用。 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
从索引列表中选择 | 定位器, *索引 | 选择从选择列表中选择 列表选项的索引从0开始。 若是为单选列表指定了多个选项,则将选择最后一个值。使用多选列表,将选择全部指定的选项,但不会清除可能的旧选择。 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
从标签列表中选择 | 定位器, *标签 | 选择从选择列表中选择 若是为单选列表指定了多个选项,则将选择最后一个值。使用多选列表,将选择全部指定的选项,但不会清除可能的旧选择。 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
从按值列出中选择 | 定位器, *值 | 选择从选择列表中选择 若是为单选列表指定了多个选项,则将选择最后一个值。使用多选列表,将选择全部指定的选项,但不会清除可能的旧选择。 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
选择单选按钮 | group_name, value | 将单选按钮组设置 要选择的单选按钮由两个参数定位:
例子:
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
选择窗口 | 定位符= MAIN | 选择浏览器窗口匹配 若是找到该窗口,则全部后续命令都将使用所选窗口,直到再次使用此关键字。若是找不到该窗口,则此关键字将失败。返回前一个窗口句柄,可用于稍后返回。 请注意,在此上下文窗口中表示在现有窗口上执行某些操做时打开的弹出窗口。没法选择使用Open Browser打开的窗口,必须使用Switch Browser。另请注意,应使用Handle Alert或其余与警报相关的关键字处理警报。 该
例:
注意:
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
设置浏览器隐式等待 | 值 | 设置Selenium使用的隐式等待值。 与Set Selenium Implicit Wait相同,但仅影响当前浏览器。 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
将焦点设置为元素 | 定位器 | 将焦点设置为标识的元素 在SeleniumLibrary 3.0以前,这个关键字被命名为Focus。 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
设置截屏目录 | path, persist = DEPRECATED | 设置捕获的屏幕截图的目录。
返回前一个值,能够在之后根据须要恢复原始值。
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
设置Selenium Implicit Wait | 值 | 设置Selenium使用的隐式等待值。 该值能够做为被认为是秒的数字给出,或者做为人类可读的字符串给出 此关键字设置全部已打开浏览器的隐式等待。使用Set Browser Implicit Wait将其设置为仅当前浏览器。 有关详细信息,请参阅上面的隐式等待部分。 例:
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
设置Selenium Speed | 值 | 设置每一个Selenium命令后等待的延迟。 该值能够做为被认为是秒的数字给出,或者做为人类可读的字符串给出 有关详细信息,请参阅上面的Selenium Speed部分。 例:
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
设置Selenium Timeout | 值 | 设置各类关键字使用的超时。 该值能够做为被认为是秒的数字给出,或者做为人类可读的字符串给出 有关详细信息,请参阅上面的超时部分。 例:
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
设置窗口位置 | x, y | 使用 该位置相对于屏幕的左上角,但某些浏览器排除了操做系统从计算中设置的可能任务栏。所以,实际位置可能因不一样浏览器而不一样。 可使用包含数字的字符串或使用实际数字来给出值。另请参见获取窗口位置。 例:
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
设置窗口大小 | 宽度, 高度 | 将当前窗口大小设置为给定 可使用包含数字的字符串或使用实际数字来给出值。另请参阅获取窗口大小。 浏览器限制了它们的设置。尝试将它们设置得更小将致使实际大小大于请求的大小。 例:
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
模拟 | 定位器, 事件 | 已过期。请改用模拟事件。 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
模拟事件 | 定位器, 事件 | 模拟 若是element具备 在SeleniumLibrary 3.0以前,这个关键字被命名为Simulate。 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
提交表格 | 定位器=无 | 提交由...标识的表格 若是 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
切换浏览器 | index_or_alias | 在活动浏览器之间切换 Open Browser关键字返回索引,而且能够显式地为其指定别名。指数从1开始。 例:
上面的示例预计在打开第一个浏览器时没有其余打开的浏览器,由于它
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
表格单元格应该包含 | locator, row, column, expected, loglevel = INFO | 验证表格单元格包含文本 有关已接受参数的说明,请参阅此关键字在内部使用的获取表单元 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
表列应包含 | locator, column, expected, loglevel = INFO | 验证表列包含文本 该表使用 列索引从1开始。可使用负索引从末尾引用列,以便-1是最后一列,-2是最后一列,依此类推。 若是表包含跨多个列的单元格,则这些合并的单元格将计为单个列。 有关参数的说明,请参见Page Should Contain Element |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
表页脚应该包含 | locator, expected, loglevel = INFO | 验证表格页脚包含文本
该表使用 有关参数的说明,请参见Page Should Contain Element |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
表头应该包含 | locator, expected, loglevel = INFO | 验证表头包含文本
该表使用 有关参数的说明,请参见Page Should Contain Element |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
表行应包含 | locator, row, expected, loglevel = INFO | 验证表行包含文本 该表使用 行索引从1开始。可使用负索引从末尾引用行,以便-1是最后一行,-2是最后一行,依此类推。 若是表包含跨越多行的单元格,则仅对这些合并单元格的最上一行进行匹配。 有关参数的说明,请参见Page Should Contain Element |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
表应该包含 | locator, expected, loglevel = INFO | 验证表包含文本 该表使用 有关参数的说明,请参见Page Should Contain Element |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Textarea应该包含 | locator, expected, message =无 | 验证文本区域
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Textarea值应该是 | locator, expected, message =无 | 验证文本区域
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Textfield应该包含 | locator, expected, message =无 | 验证文本字段
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
应该是Textfield值 | locator, expected, message =无 | 验证文本字段
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
标题应该是 | 标题, 消息=无 | 验证当前页面标题是否等于 该
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
从列表中取消选择所有 | 定位器 | 取消选择多选列表中的全部选项 SeleniumLibrary 3.0中的新功能。 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
取消选中复选框 | 定位器 | 删除选中的复选框 若是未选中该复选框,则不执行任何操做 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
取消选择框架 | 将主框架设置为当前框架。 实际上取消了以前的Select Frame调用。 |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
从列表中取消选择 | 定位器, *项目 | 已过期。使用取消选择标签/值/索引列表。 此关键字根据标签或值取消选择选项,这使得它很是复杂和缓慢。它已经在SeleniumLibrary 3.0被弃用,专用关键字取消选择从列表按标签,取消选择从列表按值并取消选择从列表按索引应改成使用。 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
从索引列表中取消选择 | 定位器, *索引 | 从选择列表中取消选择选项 列表选项的索引从0开始。此关键字仅适用于多选列表。 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
从标签列表中取消选择 | 定位器, *标签 | 从选择列表中取消选择选项 此关键字仅适用于多选列表。 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
从值列表中取消选择 | 定位器, *值 | 从选择列表中取消选择选项 此关键字仅适用于多选列表。 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
等待条件 | condition, timeout = None, error = None | 等待直到 条件能够是任意JavaScript表达式,但必须返回要评估的值。有关访问页面上的内容的信息,请参阅执行JavaScript。 若是超时在条件变为真以前到期,则失败。有关使用超时及其默认值的详细信息,请参阅超时部分。
例子:
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
等到元素包含 | locator, text, timeout = None, error = None | 等到元素 若是
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
等到元素不包含 | locator, text, timeout = None, error = None | 等到元素 若是
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
等到元素启用 | locator, timeout =无, 错误=无 | 等待元素 若是元素未禁用或只读,则认为元素已启用。 若是
考虑要禁用的只读元素是SeleniumLibrary 3.0中的新功能。 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
等到元素不可见 | locator, timeout =无, 错误=无 | 等到元素 若是
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
等到元素可见 | locator, timeout =无, 错误=无 | 等到元素 若是
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
等到页面包含 | text, timeout = None, error = None | 等到 若是
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
等到页面包含元素 | locator, timeout =无, 错误=无 | 等到元素 若是
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
等到页面不包含 | text, timeout = None, error = None | 等待直到 若是
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
等到页面不包含元素 | locator, timeout =无, 错误=无 | 等待元素 若是
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Xpath应该匹配X次 | xpath, x, message = None, loglevel = INFO | 不推荐使用,请使用Page should Contain Element with |