robotframework-seleniumlibrary 用法

*** 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 

 

Table of contents

定位元素

SeleniumLibrary中须要与网页上的元素交互的全部关键字都采用一般命名的参数来locator指定如何查找元素。大多数状况下,定位器使用下面描述的定位器语法做为字符串给出,但也能够使用WebElementscss

定位器语法

SeleniumLibrary支持基于不一样策略查找元素,例如元素id,XPath表达式或CSS选择器。可使用前缀显式指定策略,也能够隐式策略。html

默认定位器策略

默认状况下,定位器被视为使用关键字特定的默认定位器策略。全部关键字都支持基于idname属性查找元素,但某些关键字支持其上下文中有意义的其余属性或其余值。例如,Click Link支持href属性和连接文本以及正常id和添加namepython

Examples:jquery

Click Element example # Match based on id or name匹配基于idname
Click Link example # Match also based on link text and href.匹配也基于连接文本和href
Click Button example # Match based on idname or value. 匹配基于idnamevalue

若是定位器意外地以识别为显式定位器策略隐式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:fooid: fooid : 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不稳定,则须要使用其余解决方案。若是一个元素都有一个惟一的标签名称或类别,使用tagclasscss策略同样tag:h1class: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库。
  • 此前SeleniumLibrary 3.0,表相关的关键字仅支持xpathcsssizzle/jquery战略。

隐式XPath策略

若是定位器以//或开头(//,则定位器被视为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.

使用WebElements

除了将定位器指定为字符串以外,还可使用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文档

请参阅如下时间格式以获取支持的语

Time format

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 falseno 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.

 

Importing

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.

  • timeout: Default value for timeouts used with Wait ... keywords.
  • implicit_wait: Default value for implicit wait used when locating elements.
  • run_on_failure: Default action for the run-on-failure functionality.
  • screenshot_root_directory: Location where possible screenshots are created. If not given, the directory where the log file is written is used.

 

Shortcuts 快捷键

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次

Keywords 关键词

Keyword Arguments Documentation
Add Cookie 添加Cookie name, value, path=None,domain=None, secure=None,expiry=None

Adds a cookie to your current session.

name and value are required, pathdomainsecure and expiry are optional. Expiry supports the same formats as the DateTime library or an epoch time stamp.

Example:

Add Cookie foo bar    
Add Cookie foo bar domain=example.com  
Add Cookie foo bar expiry=2027-09-28 16:21:35 # Expiry as timestamp.
Add Cookie foo bar expiry=1822137695 # Expiry as epoch seconds.

Prior to SeleniumLibrary 3.0 setting expiry did not work.

Add Location Strategy 添加位置策略 strategy_name, strategy_keyword,persist=False

添加自定义位置策略。

有关如何建立和使用自定义策略的信息,请参阅自定义定位器删除位置策略可用于删除已注册的策略。

默认状况下,在离开当前做用域后会自动删除位置策略。设置persist为真值(请参阅布尔参数)将致使位置策略在整个测试期间保持注册状态。

Alert Should Be Present 警报应该存在 text=, action=ACCEPT, timeout=None

验证是否存在警报,而且默认状况下接受警报。

若是没有警报则失败。若是text是非空字符串,则它用于验证警报的消息。默认状况下接受警报,但可使用actionHandle Alert相同的方式控制该行为。

timeout指定等待警报显示的时间。若是未给出,则使用全局默认超时

actiontimeout参数是SeleniumLibrary 3.0中的新功能。在早期版本中,始终接受警报,并将超时硬编码为一秒。

Alert Should Not Be Present 警报不该该存在 action=ACCEPT, timeout=0


验证没有警报。

若是警报确实存在,则action参数肯定应如何处理。默认状况下,警报被接受,但也可使用与Handle Alert关键字相同的方式将其解除或保持打开状态。

timeout指定等待警报显示的时间。默认状况下,警报根本不会等待,但若是警报可能会延迟,则能够给出自定义时间。有关语法的信息,请参阅时间格式部分。

SeleniumLibrary 3.0中的新功能。

Assign Id To Element locator, id

将临时分配id给指定的元素locator

若是定位器是复杂的和/或缓慢的XPath表达式而且须要屡次,则这很是有用。标识符在从新加载页面时到期。

有关定位器语法的详细信息,请参阅定位元素部分

Example:

Assign ID to Element //ul[@class='example' and ./li[contains(., 'Stuff')]] my id
Page Should Contain Element my id  
Capture Page Screenshot 捕获页面截图 filename=selenium-screenshot-{index}.png

获取当前页面的屏幕截图并将其嵌入到日志文件中。

filenameargument指定要将屏幕截图写入的文件的名称。保存屏幕截图的目录能够在导入库时使用,也可使用Set Screenshot Directory关键字进行设置。若是未配置目录,则屏幕截图将保存到写入Robot Framework日志文件的同一目录中。

从SeleniumLibrary 1.8开始,若是filename包含marker {index},它将自动替换为惟一的运行索引,以防止文件被覆盖。索引从1开始,它们的表示方式可使用Python的格式字符串语法进行自定义。

返回建立的屏幕截图文件的绝对路径

Examples:

Capture Page Screenshot  
File Should Exist ${OUTPUTDIR}/selenium-screenshot-1.png
${path} = Capture Page Screenshot
File Should Exist ${OUTPUTDIR}/selenium-screenshot-2.png
File Should Exist ${path}
Capture Page Screenshot custom_name.png
File Should Exist ${OUTPUTDIR}/custom_name.png
Capture Page Screenshot custom_with_index_{index}.png
File Should Exist ${OUTPUTDIR}/custom_with_index_1.png
Capture Page Screenshot formatted_index_{index:03}.png
File Should Exist ${OUTPUTDIR}/formatted_index_001.png
捕获页面截图文件应该存在$ {} OUTPUTDIR /selenium-screenshot-1.png$ {path} =捕获页面截图文件应该存在$ {} OUTPUTDIR /selenium-screenshot-2.png文件应该存在$ {PATH}捕获页面截图custom_name.png文件应该存在$ {} OUTPUTDIR /custom_name.png捕获页面截图custom_with_index_ {索引} .PNG文件应该存在$ {} OUTPUTDIR /custom_with_index_1.png捕获页面截图formatted_index_ {指数:03}巴纽文件应该存在$ {} OUTPUTDIR /formatted_index_001.png 
Checkbox Should Be Selected 应选中复选框 locator

locator选中/选中验证复选框。

See the Locating elements section for details about the locator syntax.

Checkbox Should Not Be Selected不该选中复选框 locator

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

输入file_path到文件输入字段locator

此关键字最经常使用于将文件输入上载表单。指定的文件file_path必须在执行测试的机器上可用

 

Example:

Choose File my_upload_field ${CURDIR}/trades.csv
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

清除标识的文本输入元素的值locator

See the Locating elements section for details about the locator syntax.

Click Button 单击按钮 locator

点击按钮标识locator

See the Locating elements section for details about the locator syntax. When using the default locator strategy, buttons are searched using idname and value.

Click Element 单击元素 locator

单击标识的元素locator

See the Locating elements section for details about the locator syntax.

Click Element At Coordinates 单击坐标处的元素 locator, xoffset, yoffset


点击元素locatorxoffset/yoffset

移动光标,从该点计算元素的中心和x / y坐标。

See the Locating elements section for details about the locator syntax.

Click Image 单击图像 locator

单击标识的图像locator

See the Locating elements section for details about the locator syntax. When using the default locator strategy, images are searched using idnamesrcand alt.

Click Link 单击连接 locator

单击标识的连接locator

See the Locating elements section for details about the locator syntax. When using the default locator strategy, links are searched using idnamehrefand the link text.

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.

driver_name must be an WebDriver implementation name like Firefox, Chrome, Ie, Opera, Safari, PhantomJS, or Remote.

The initialized WebDriver can be configured either with a Python dictionary kwargs or by using keyword arguments **init_kwargs. These arguments are passed directly to WebDriver without any processing. See Selenium API documentation for details about the supported arguments.

Examples:

# Use proxy with Firefox      
${proxy}= Evaluate sys.modules['selenium.webdriver'].Proxy() sys, selenium.webdriver
${proxy.http_proxy}= Set Variable localhost:8888  
Create Webdriver Firefox proxy=${proxy}  
# Use proxy with PhantomJS      
${service args}= Create List --proxy=192.168.132.104:8888  
Create Webdriver PhantomJS service_args=${service args}  

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

验证当前帧是否包含text

See Page Should Contain for explanation about the loglevel argument.

Prior to SeleniumLibrary 3.0 this keyword was named Current Frame Contains.

Current Frame Should Not Contain 当前框架不该包含 text, loglevel=INFO

验证当前帧是否包含text

See Page Should Contain for explanation about the loglevel argument.

Delete All Cookies删除全部Cookie   删除全部cookie。
Delete Cookie 删除Cookie name

删除cookie匹配name

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 Ok). accept can be set to a false value to dismiss the alert (i.e. to press Cancel).

Handle Alert has better support for controlling should the alert be accepted, dismissed, or left open.

Double Click Element 双击元素 locator

双击标识的元素locator

See the Locating elements section for details about the locator syntax.

Drag And Drop 拖放 locator, target

drags元素由locatorinto target元素标识。

locator参数是拖动的元素的定位器和target是目标的定位器。有关定位器语法的详细信息,请参阅定位元素部分。

 

Example:

Drag And Drop css:div#element css:div.target

拖放CSS:DIV元素#CSS:div.target

 

Drag And Drop By Offset经过偏移拖放 locator, xoffset, yoffset

拖拽元素locatorxoffset/yoffset

有关定位器语法的详细信息,请参阅定位元素部分。

元素将被移动,xoffset而且yoffset每一个元素都是指定偏移量的负数或正数

Example:

Drag And Drop By Offset myElem 50 -35 # Move myElem 50px right and 35px down

 

经过偏移拖放myElem50-35#向右移动myElem 50px,向下移动35px

Element Should Be Disabled 元素应该被禁用 locator

验证标识的元素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

验证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

验证标识的元素locator是否为焦点。

See the Locating elements section for details about the locator syntax.

New in SeleniumLibrary 3.0.

Element Should Be Visible 元素应该是可见的 locator, message=None

验证标识的元素locator是否可见。

这里,visible表示该元素在逻辑上可见,在当前浏览器视口中不是光学可见的。例如,携带的元素在display:none逻辑上不可见,所以在该元素上使用此关键字将失败。

有关定位器语法的详细信息,请参阅定位元素部分。

message参数可用于覆盖默认错误消息。

Element Should Contain 元素应该包含 locator, expected, message=None,ignore_case=False


验证该元素是否locator包含文本expected

有关定位器语法的详细信息,请参阅定位元素部分。

message参数可用于覆盖默认错误消息。

ignore_case参数能够设置为True比较不区分大小写,默认值为False。SeleniumLibrary 3.1中的新功能。

ignore_case SeleniumLibrary 3.1中的新参数。

若是要匹配确切的文本而不是子字符串,则应使用元素文本

Element Should Not Be Visible locator, message=None

验证标识的元素locator是否不可见

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

验证该元素locator不包含文本expected

有关定位器语法的详细信息,请参阅定位元素部分。

message参数可用于覆盖默认错误消息。

ignore_case参数能够设置为True比较不区分大小写,默认值为False。

ignore_case SeleniumLibrary 3.1中的新参数。

Element Text Should Be 元素文本应该是 locator, expected, message=None,ignore_case=False

验证该元素是否locator包含确切的文本expected

有关定位器语法的详细信息,请参阅定位元素部分。

message参数可用于覆盖默认错误消息。

ignore_case参数能够设置为True比较不区分大小写,默认值为False。

ignore_case SeleniumLibrary 3.1中的新参数。

若是须要子字符串匹配,则使用元素应包含

Element Text Should Not Be 元素文本不该该 locator, not_expected, message=None,ignore_case=False

验证该元素locator不包含确切的文本not_expected

有关定位器语法的详细信息,请参阅定位元素部分。

message参数可用于覆盖默认错误消息。

ignore_case参数能够设置为True比较不区分大小写,默认值为False。

SeleniumLibrary 3.1.1中的新功能

Execute Async Javascript 执行异步Javascript *code

执行异步JavaScript代码。

Execute Javascript相似,不一样之处在于使用此关键字执行的脚本必须经过调用提供的回调明确表示它们已完成。此回调始终做为最后一个参数注入到执行的函数中。

脚本必须在脚本超时内完成,不然此关键字将失败。有关详细信息,请参阅超时部分。

Examples:

Execute Async JavaScript var callback = arguments[arguments.length - 1]; window.setTimeout(callback, 2000);  
Execute Async JavaScript ${CURDIR}/async_js_to_execute.js  
${result} = Execute Async JavaScript  
... var callback = arguments[arguments.length - 1];  
... function answer(){callback("text");};  
... window.setTimeout(answer, 2000);  
Should Be Equal ${result} text
Execute Javascript 执行Javascript *code

执行给定的JavaScript代码。

code能够包含多行代码,而且能够在测试数据中分红多个单元。在这种状况下,部件链接在一块儿而不添加空格。

若是code是现有文件的绝对路径,则将从该文件中读取要执行的JavaScript。正斜杠用做全部操做系统上的路径分隔符。

JavaScript在当前选定的框架或窗口的上下文中执行,做为匿名函数的主体。用window指应用程序的窗口,并document指当前帧或窗口,例如文档对象document.getElementById('example')

此关键字返回执行的JavaScript代码返回的任何内容。返回值将转换为适当的Python类型。

Examples:

Execute JavaScript window.myFunc('arg1', 'arg2')  
Execute JavaScript ${CURDIR}/js_to_execute.js  
${sum} = Execute JavaScript return 1 + 1;
Should Be Equal ${sum} ${2}
Focus locator

已过期. Use Set Focus To Element instead.

Frame Should Contain 框架应该包含 locator, text, loglevel=INFO

验证由locatorcontains 标识的帧text

有关定位器语法的详细信息,请参阅定位元素部分。

See Page Should Contain for explanation about the loglevel argument.

Get Alert Message 获取提醒消息 dismiss=True

过期. Use Handle Alert instead.

Returns the message the alert has. Dismisses the alert by default (i.e. presses Cancel) and setting dismiss to false leaves the alert open. There is no support to accept the alert (i.e. to press Ok).

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 name as an object.

If no cookie is found with name, keyword fails. The cookie object contains details about the cookie. Attributes available in the object are documented in the table below.

Attribute Explanation
name The name of a cookie.
value Value of the cookie.
path Indicates a URL path, for example /.
domain The domain the cookie is visible to.
secure When true, cookie is only used with HTTPS connections.
httpOnly When true, cookie is not accessible via JavaScript.
expiry Python datetime object indicating when the cookie expires.

See the WebDriver specification for details about the cookie information. Notice that expiry is specified as a datetime object, not as seconds since Unix Epoch like WebDriver natively does.

Example:

Add Cookie foo bar
${cookie} = Get Cookie foo
Should Be Equal ${cookie.name} bar
Should Be Equal ${cookie.value} foo
Should Be True ${cookie.expiry.year} > 2017  

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 name1=value1; name2=value2; name3=value3. It can be used, for example, for logging purposes or in headers when sending HTTP requests.

Get Element Attribute locator, attribute=None

Returns value of attribute from element locator.

See the Locating elements section for details about the locator syntax.

Example:

${id}= Get Element Attribute css:h1 id

Passing attribute name as part of the locator is deprecated since SeleniumLibrary 3.0. The explicit attribute argument should be used instead.

Get Element Count locator

Returns number of elements matching locator.

If you wish to assert the number of matching elements, use Page Should Contain Element with limit argument. Keyword will always return an integer.

Example:

${count} = Get Element Count name:div_name
Should Be True ${count} > 2  

New in SeleniumLibrary 3.0.

Get Element Size locator

Returns width and height of element identified by locator.

See the Locating elements section for details about the locator syntax.

Both width and height are returned as integers.

Example:

${width} ${height} = Get Element Size css:div#container
Get Horizontal Position locator

Returns horizontal position of element identified by locator.

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 locator.

See the Locating elements section for details about the locator syntax.

Returns visible labels by default, but values can be returned by setting the values argument to a true value (see Boolean arguments).

Example:

${labels} = Get List Items mylist  
${values} = Get List Items css:#example select values=True

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 locator.

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 locator.

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 locator.

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 locator.

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 1 second.

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 1 second.

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 1 second.

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 locator argument and its cell found using row and column. See the Locating elements section for details about the locator syntax.

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 <th> and <td> elements anywhere in the table are considered to be cells.

See Page Should Contain for explanation about the loglevel argument.

Get Text locator

Returns the text value of element identified by locator.

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 locator.

See the Locating elements section for details about the locator syntax.

Get Vertical Position locator

Returns vertical position of element identified by locator.

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 locator.

See the Locating elements section for details about the locator syntax.

Get WebElements locator

Returns list of WebElement objects matching the locator.

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:

${x} ${y}= Get Window Position
Get Window Size  

Returns current window width and height as integers.

See also Set Window Size.

Example:

${width} ${height}= Get Window Size
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 url.

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 action argument that supports the following case-insensitive values:

  • ACCEPT: Accept the alert i.e. press Ok. Default.
  • DISMISS: Dismiss the alert i.e. press Cancel.
  • LEAVE: Leave the alert open.

The timeout argument specifies how long to wait for the alert to appear. If it is not given, the global default timeout is used instead.

Examples:

Handle Alert     # Accept alert.
Handle Alert action=DISMISS   # Dismiss alert.
Handle Alert timeout=10 s   # Use custom timeout and accept alert.
Handle Alert DISMISS 1 min # Use custom timeout and dismiss alert.
${message} = Handle Alert   # Accept alert and get its message.
${message} = Handle Alert LEAVE # Leave alert open and get its message.

New in SeleniumLibrary 3.0.

Input Password locator, password

Types the given password into text field identified by locator.

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

Input Password password_field password

the password is shown as a normal keyword argument. A way to avoid that is using variables like

Input Password password_field ${PASSWORD}

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 text into text field identified by locator.

Use Input Password if you do not want the given text to be logged.

See the Locating elements section for details about the locator syntax.

Input Text Into Alert text, action=ACCEPT, timeout=None

Types the given text into an input field in an alert.

The alert is accepted by default, but that behavior can be controlled by using the action argument same way as with Handle Alert.

timeout specifies how long to wait for the alert to appear. If it is not given, the global default timeout is used instead.

New in SeleniumLibrary 3.0.

Input Text Into Prompt text

Deprecated. Use Input Text Into Alert instead.

Types the given text into an input field in an alert. Leaves the alert open.

List Selection Should Be locator, *expected

Verifies selection list locator has expected options selected.

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 Selection Should Be gender Female  
List Selection Should Be interests Test Automation Python
List Should Have No Selections locator

Verifies selection list locator has no options selected.

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 url.

Location Should Contain expected

Verifies that current URL contains expected.

Locator Should Match X Times locator, x, message=None,loglevel=INFO

Deprecated, use Page Should Contain Element with limit argument instead.

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 loglevel argument defines the used log level. Valid log levels are WARNINFO (default), DEBUG, and NONE (no logging).

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 locator.

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 locator.

See the Locating elements section for details about the locator syntax. When using the default locator strategy, images are searched using idnamesrcand alt.

Mouse Down On Link locator

Simulates a mouse down event on a link identified by locator.

See the Locating elements section for details about the locator syntax. When using the default locator strategy, links are searched using idnamehrefand the link text.

Mouse Out locator

Simulates moving mouse away from the element locator.

See the Locating elements section for details about the locator syntax.

Mouse Over locator

Simulates hovering mouse over the element locator.

See the Locating elements section for details about the locator syntax.

Mouse Up locator

Simulates releasing the left mouse button on the element locator.

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 url.

The browser argument specifies which browser to use, and the supported browser are listed in the table below. The browser names are case-insensitive and some browsers have multiple supported names.

Browser Name(s)
Firefox firefox, ff
Google Chrome googlechrome, chrome, gc
Headless Firefox headlessfirefox
Headless Chrome headlesschrome
Internet Explorer internetexplorer, ie
Edge edge
Safari safari
Opera opera
Android android
Iphone iphone
PhantomJS phantomjs
HTMLUnit htmlunit
HTMLUnit with Javascript htmlunitwithjs

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 alias is an alias given for this browser instance and it can be used for switching between browsers. An alternative approach for switching is using an index returned by this keyword. These indices start from 1, are incremented when new browsers are opened, and reset back to 1 when Close All Browsers is called. See Switch Browser for more information and examples.

Optional remote_url is the URL for a Selenium Grid.

Optional desired_capabilities can be used to configure, for example, logging preferences for a browser or a browser and operating system when using Sauce Labs. Desired capabilities can be given either as a Python dictionary or as a string in format key1:value1,key2:value2Selenium documentation lists possible capabilities that can be enabled.

Optional ff_profile_dir is the path to the Firefox profile directory if you wish to overwrite the default profile Selenium uses. Notice that prior to SeleniumLibrary 3.0, the library contained its own profile that was used by default.

Examples:

Open Browser http://example.com Chrome  
Open Browser http://example.com Firefox alias=Firefox
Open Browser http://example.com Edge remote_url=http://127.0.0.1:4444/wd/hub

If the provided configuration options are not enough, it is possible to use Create Webdriver to customize browser initialization even more.

Applying desired_capabilities argument also for local browser is new in SeleniumLibrary 3.1.

Open Context Menu locator

Opens context menu on element identified by locator.

Page Should Contain text, loglevel=INFO

Verifies that current page contains text.

If this keyword fails, it automatically logs the page source using the log level specified with the optional loglevel argument. Valid log levels are DEBUGINFO (default), WARN, and NONE. If the log level is NONE or below the current active log level the source will not be logged.

Page Should Contain Button locator, message=None, loglevel=INFO

Verifies button locator is found from current page.

See Page Should Contain Element for explanation about message and loglevel arguments.

See the Locating elements section for details about the locator syntax. When using the default locator strategy, buttons are searched using idname and value.

Page Should Contain Checkbox locator, message=None, loglevel=INFO

Verifies checkbox locator is found from current page.

See Page Should Contain Element for explanation about message and loglevel arguments.

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 locator is found on the current page.

See the Locating elements section for details about the locator syntax.

The message argument can be used to override the default error message.

The limit argument can used to define how many elements the page should contain. When limit is None (default) page can contain one or more elements. When limit is a number, page must contain same number of elements.

See Page Should Contain for explanation about the loglevel argument.

Examples assumes that locator matches to two elements.

Page Should Contain Element div_name limit=1 # Keyword fails.
Page Should Contain Element div_name limit=2 # Keyword passes.
Page Should Contain Element div_name limit=none # None is considered one or more.
Page Should Contain Element div_name   # Same as above.

The limit argument is new in SeleniumLibrary 3.0.

Page Should Contain Image locator, message=None, loglevel=INFO

Verifies image identified by locator is found from current page.

See the Locating elements section for details about the locator syntax. When using the default locator strategy, images are searched using idnamesrcand alt.

See Page Should Contain Element for explanation about message and loglevel arguments.

Page Should Contain Link locator, message=None, loglevel=INFO

Verifies link identified by locator is found from current page.

See the Locating elements section for details about the locator syntax. When using the default locator strategy, links are searched using idnamehrefand the link text.

See Page Should Contain Element for explanation about message and loglevel arguments.

Page Should Contain List locator, message=None, loglevel=INFO

Verifies selection list locator is found from current page.

See Page Should Contain Element for explanation about message and loglevel arguments.

See the Locating elements section for details about the locator syntax.

Page Should Contain Radio Button locator, message=None, loglevel=INFO

Verifies radio button locator is found from current page.

See Page Should Contain Element for explanation about message and loglevel arguments.

See the Locating elements section for details about the locator syntax. When using the default locator strategy, radio buttons are searched using idnameand value.

Page Should Contain Textfield locator, message=None, loglevel=INFO

Verifies text field locator is found from current page.

See Page Should Contain Element for explanation about message and loglevel arguments.

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 text.

See Page Should Contain for explanation about the loglevel argument.

Page Should Not Contain Button locator, message=None, loglevel=INFO

Verifies button locator is not found from current page.

See Page Should Contain Element for explanation about message and loglevel arguments.

See the Locating elements section for details about the locator syntax. When using the default locator strategy, buttons are searched using idname and value.

Page Should Not Contain Checkbox locator, message=None, loglevel=INFO

Verifies checkbox locator is not found from current page.

See Page Should Contain Element for explanation about message and loglevel arguments.

See the Locating elements section for details about the locator syntax.

Page Should Not Contain Element locator, message=None, loglevel=INFO

Verifies that element locator is found on the current page.

See the Locating elements section for details about the locator syntax.

See Page Should Contain for explanation about message and loglevel arguments.

Page Should Not Contain Image locator, message=None, loglevel=INFO

Verifies image identified by locator is found from current page.

See the Locating elements section for details about the locator syntax. When using the default locator strategy, images are searched using idnamesrcand alt.

See Page Should Contain Element for explanation about message and loglevel arguments.

Page Should Not Contain Link locator, message=None, loglevel=INFO

Verifies link identified by locator is not found from current page.

See the Locating elements section for details about the locator syntax. When using the default locator strategy, links are searched using idnamehrefand the link text.

See Page Should Contain Element for explanation about message and loglevel arguments.

Page Should Not Contain List locator, message=None, loglevel=INFO

Verifies selection list locator is not found from current page.

See Page Should Contain Element for explanation about message and loglevel arguments.

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 locator is not found from current page.

See Page Should Contain Element for explanation about message and loglevel arguments.

See the Locating elements section for details about the locator syntax. When using the default locator strategy, radio buttons are searched using idnameand value.

Page Should Not Contain Textfield locator, message=None, loglevel=INFO

Verifies text field locator is not found from current page.

See Page Should Contain Element for explanation about message and loglevel arguments.

See the Locating elements section for details about the locator syntax.

Press Key locator, key

Simulates user pressing key on element identified by locator.

See the Locating elements section for details about the locator syntax.

key is either a single character, a string, or a numerical ASCII code of the key lead by '\\'.

Examples:

Press Key text_field q  
Press Key text_field abcde  
Press Key login_button \\13 # ASCII code for enter key
Radio Button Should Be Set To group_name, value

Verifies radio button group group_name is set to value.

group_name is the name of the radio button group.

Radio Button Should Not Be Selected group_name

Verifies radio button group group_name has no selection.

group_name is the name of the radio button group.

Register Keyword To Run On Failure keyword

Sets the keyword to execute when a SeleniumLibrary keyword fails.

keyword is the name of a keyword that will be executed if a SeleniumLibrary keyword fails. It is possible to use any available keyword, including user keywords or keywords from other libraries, but the keyword must not take any arguments.

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 NOTHING or NONE, case-insensitively, as well as Python None to disable this feature altogether.

This keyword returns the name of the previously registered failure keyword or Python None if this functionality was previously disabled. The return value can be always used to restore the original value later.

Example:

Register Keyword To Run On Failure Log Source  
${previous kw}= Register Keyword To Run On Failure NONE
Register Keyword To Run On Failure ${previous kw}  

Changes in SeleniumLibrary 3.0:

  • Possible to use string NONE or Python None to disable the functionality.
  • Return Python None when the functionality was disabled earlier. In previous versions special value No Keyword was returned and it could not be used to restore the original state.
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 locator.

See the Locating elements section for details about the locator syntax.

Select Checkbox locator

Selects checkbox identified by locator.

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 locator as the current frame.

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 Frame top-frame # Select frame with id or name 'top-frame'
Click Link example # Click link 'example' in the selected frame
Unselect Frame   # Back to main frame.
Select Frame //iframe[@name='xxx'] # Select frame using xpath
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 LabelSelect 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 locator by indexes.

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 locator by labels.

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 locator by values.

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 group_name to value.

The radio button to be selected is located by two arguments:

  • group_name is the name of the radio button group.
  • value is the id or value attribute of the actual radio button.

Examples:

Select Radio Button size XL
Select Radio Button contact email
Select Window locator=MAIN

Selects browser window matching locator.

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 BrowserSwitch Browser must be used instead. Notice also that alerts should be handled with Handle Alert or other alert related keywords.

The locator can be specified using different strategies somewhat similarly as when locating elements on pages.

  • By default the locator is matched against window handle, name, title, and URL. Matching is done in that order and the the first matching window is selected.
  • The locator can specify an explicit strategy by using format strategy:value (recommended) or strategy=value. Supported strategies are nametitle and url, which match windows using name, title, and URL, respectively. Additionally, default can be used to explicitly use the default strategy explained above.
  • If the locator is NEW (case-insensitive), the latest opened window is selected. It is an error if this is the same as the current window.
  • If the locator is MAIN (default, case-insensitive), the main window is selected.
  • If the locator is CURRENT (case-insensitive), nothing is done. This effectively just returns the current window handle.
  • If the locator is not a string, it is expected to be a list of window handles to exclude. Such a list of excluded windows can be get from Get Window Handles prior to doing an action that opens a new window.

Example:

Click Link popup1   # Open new window
Select Window example   # Select window using default strategy
Title Should Be Pop-up 1    
Click Button popup2   # Open another window
${handle} = Select Window NEW # Select latest opened window
Title Should Be Pop-up 2    
Select Window ${handle}   # Select window using handle
Title Should Be Pop-up 1    
Select Window MAIN   # Select the main window
Title Should Be Main    
${excludes} = Get Window Handles   # Get list of current windows
Click Link popup3   # Open one more window
Select Window ${excludes}   # Select window using excludes
Title Should Be Pop-up 3    

NOTE:

  • The strategy:value syntax is only supported by SeleniumLibrary 3.0 and newer.
  • Earlier versions supported aliases Nonenull and the empty string for selecting the main window, and alias self for selecting the current window. These aliases were deprecated in SeleniumLibrary 3.0.
  • Prior to SeleniumLibrary 3.0 matching windows by name, title and URL was case-insensitive.
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 locator.

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.

path argument specifies the absolute path to a directory where the screenshots should be written to. If the directory does not exist, it will be created. The directory can also be set when importing the library. If it is not configured anywhere, screenshots are saved to the same directory where Robot Framework's log file is written.

persist argument is deprecated and has no effect.

The previous value is returned and can be used to restore the original value later if needed.

Deprecating persist and returning the previous value are new in SeleniumLibrary 3.0.

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 1 second. The previous value is returned and can be used to restore the original value later if needed.

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:

${orig wait} = Set Selenium Implicit Wait 10 seconds
Perform AJAX call that is slow    
Set Selenium Implicit Wait ${orig wait}  
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 1 second. The previous value is returned and can be used to restore the original value later if needed.

See the Selenium Speed section above for more information.

Example:

Set Selenium Speed 0.5 seconds
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 1 second. The previous value is returned and can be used to restore the original value later if needed.

See the Timeout section above for more information.

Example:

${orig timeout} = Set Selenium Timeout 15 seconds
Open page that loads slowly    
Set Selenium Timeout ${orig timeout}  
Set Window Position x, y

Sets window position using x and y coordinates.

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 Position 100 200
Set Window Size width, height

Sets current windows size to given width and height.

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:

Set Window Size 800 600
Simulate locator, event

Deprecated. Use Simulate Event instead.

Simulate Event locator, event

Simulates event on element identified by locator.

This keyword is useful if element has OnEvent handler that needs to be explicitly invoked.

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 locator.

If locator is not given, first form on the page is submitted.

See the Locating elements section for details about the locator syntax.

Switch Browser index_or_alias

Switches between active browsers using index_or_alias.

Indices are returned by the Open Browser keyword and aliases can be given to it explicitly. Indices start from 1.

Example:

Open Browser http://google.com ff  
Location Should Be http://google.com    
Open Browser http://yahoo.com ie alias=second
Location Should Be http://yahoo.com    
Switch Browser 1 # index  
Page Should Contain I'm feeling lucky    
Switch Browser second # alias  
Page Should Contain More Yahoo!    
Close All Browsers      

Above example expects that there was no other open browsers when opening the first one because it used index 1 when switching to it later. If you are not sure about that, you can store the index into a variable as below.

${index} = Open Browser http://google.com
# Do something ...    
Switch Browser ${index}  
Table Cell Should Contain locator, row, column, expected,loglevel=INFO

Verifies table cell contains text expected.

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 expected.

The table is located using the locator argument and its column found using column. See the Locating elements section for details about the locator syntax.

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 loglevel argument.

Table Footer Should Contain locator, expected, loglevel=INFO

Verifies table footer contains text expected.

Any <td> element inside <tfoot> element is considered to be part of the footer.

The table is located using the locator argument. See the Locating elements section for details about the locator syntax.

See Page Should Contain Element for explanation about the loglevel argument.

Table Header Should Contain locator, expected, loglevel=INFO

Verifies table header contains text expected.

Any <th> element anywhere in the table is considered to be part of the header.

The table is located using the locator argument. See the Locating elements section for details about the locator syntax.

See Page Should Contain Element for explanation about the loglevel argument.

Table Row Should Contain locator, row, expected, loglevel=INFO

Verifies that table row contains text expected.

The table is located using the locator argument and its column found using column. See the Locating elements section for details about the locator syntax.

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 loglevel argument.

Table Should Contain locator, expected, loglevel=INFO

Verifies table contains text expected.

The table is located using the locator argument. See the Locating elements section for details about the locator syntax.

See Page Should Contain Element for explanation about the loglevel argument.

Textarea Should Contain locator, expected, message=None

Verifies text area locator contains text expected.

message can be used to override default error message.

See the Locating elements section for details about the locator syntax.

Textarea Value Should Be locator, expected, message=None

Verifies text area locator has exactly text expected.

message can be used to override default error message.

See the Locating elements section for details about the locator syntax.

Textfield Should Contain locator, expected, message=None

Verifies text field locator contains text expected.

message can be used to override the default error message.

See the Locating elements section for details about the locator syntax.

Textfield Value Should Be locator, expected, message=None

Verifies text field locator has exactly text expected.

message can be used to override default error message.

See the Locating elements section for details about the locator syntax.

Title Should Be title, message=None

Verifies that current page title equals title.

The message argument can be used to override the default error message.

message argument is new in SeleniumLibrary 3.1.

Unselect All From List locator

Unselects all options from multi-selection list locator.

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 locator.

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 LabelUnselect 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 locator by indexes.

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 locator by labels.

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 locator by values.

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 condition is true or timeout expires.

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.

error can be used to override the default error message.

Examples:

Wait For Condition return document.title == "New Title"
Wait For Condition return jQuery.active == 0
Wait For Condition style = document.querySelector('h1').style; return style.background == "red" && style.color == "white"
Wait Until Element Contains locator, text, timeout=None,error=None

Waits until element locator contains text.

Fails if timeout expires before the text appears. See the Timeouts section for more information about using timeouts and their default value and the Locating elements section for details about the locator syntax.

error can be used to override the default error message.

Wait Until Element Does Not Contain locator, text, timeout=None,error=None

Waits until element locator does not contain text.

Fails if timeout expires before the text disappears. See the Timeouts section for more information about using timeouts and their default value and the Locating elements section for details about the locator syntax.

error can be used to override the default error message.

Wait Until Element Is Enabled locator, timeout=None, error=None

Waits until element locator is enabled.

Element is considered enabled if it is not disabled nor read-only.

Fails if timeout expires before the element is enabled. See the Timeouts section for more information about using timeouts and their default value and the Locating elements section for details about the locator syntax.

error can be used to override the default error message.

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 locator is not visible.

Fails if timeout expires before the element is not visible. See the Timeouts section for more information about using timeouts and their default value and the Locating elements section for details about the locator syntax.

error can be used to override the default error message.

Wait Until Element Is Visible locator, timeout=None, error=None

Waits until element locator is visible.

Fails if timeout expires before the element is visible. See the Timeouts section for more information about using timeouts and their default value and the Locating elements section for details about the locator syntax.

error can be used to override the default error message.

Wait Until Page Contains text, timeout=None, error=None

Waits until text appears on current page.

Fails if timeout expires before the text appears. See the Timeouts section for more information about using timeouts and their default value.

error can be used to override the default error message.

Wait Until Page Contains Element locator, timeout=None, error=None

Waits until element locator appears on current page.

Fails if timeout expires before the element appears. See the Timeouts section for more information about using timeouts and their default value and the Locating elements section for details about the locator syntax.

error can be used to override the default error message.

Wait Until Page Does Not Contain text, timeout=None, error=None

Waits until text disappears from current page.

Fails if timeout expires before the text disappears. See the Timeouts section for more information about using timeouts and their default value.

error can be used to override the default error message.

Wait Until Page Does Not Contain Element locator, timeout=None, error=None

Waits until element locator disappears from current page.

Fails if timeout expires before the element disappears. See the Timeouts section for more information about using timeouts and their default value and the Locating elements section for details about the locator syntax.

error can be used to override the default error message.

Xpath Should Match X Times xpath, x, message=None,loglevel=INFO

Deprecated, use Page Should Contain Element with limit argument instead.

 

 

 

关键词 参数 文档
添加Cookie name, value, path = None, domain = None, secure = None, expiry = None

在当前会话中添加cookie。

namevalue须要,pathdomainsecureexpiry是可选的。Expiry支持与DateTime库或纪元时间戳相同的格式。

例:

添加Cookie FOO 酒吧    
添加Cookie FOO 酒吧 域= example.com  
添加Cookie FOO 酒吧 到期= 2027-09-28 16:21:35 #到期为时间戳。
添加Cookie FOO 酒吧 期满= 1822137695 #到期为纪元秒。

在SeleniumLibrary 3.0设置到期以前不起做用。

添加位置策略 strategy_name, strategy_keyword, persist = False

添加自定义位置策略。

有关如何建立和使用自定义策略的信息,请参阅自定义定位器删除位置策略可用于删除已注册的策略。

默认状况下,在离开当前做用域后会自动删除位置策略。设置persist为真值(请参阅布尔参数)将致使位置策略在整个测试期间保持注册状态。

警报应该存在 text =, action = ACCEPT, timeout = None

验证是否存在警报,而且默认状况下接受警报。

若是没有警报则失败。若是text是非空字符串,则它用于验证警报的消息。默认状况下接受警报,但可使用actionHandle Alert相同的方式控制该行为。

timeout指定等待警报显示的时间。若是未给出,则使用全局默认超时

actiontimeout参数是SeleniumLibrary 3.0中的新功能。在早期版本中,始终接受警报,并将超时硬编码为一秒。

警报不该该存在 action = ACCEPT, timeout = 0

验证没有警报。

若是警报确实存在,则action参数肯定应如何处理。默认状况下,警报被接受,但也可使用与Handle Alert关键字相同的方式将其解除或保持打开状态。

timeout指定等待警报显示的时间。默认状况下,警报根本不会等待,但若是警报可能会延迟,则能够给出自定义时间。有关语法的信息,请参阅时间格式部分。

SeleniumLibrary 3.0中的新功能。

将Id分配给元素 定位器, 身份

将临时分配id给指定的元素locator

若是定位器是复杂的和/或缓慢的XPath表达式而且须要屡次,则这很是有用。标识符在从新加载页面时到期。

有关定位器语法的详细信息,请参阅定位元素部分。

例:

为ID分配ID // ul [@ class ='example'和./li [contains(。,'Stuff')]] 个人身份
页面应包含元素 个人身份  
捕获页面截图 文件名=硒 - screenshot- {索引} .PNG

获取当前页面的屏幕截图并将其嵌入到日志文件中。

filenameargument指定要将屏幕截图写入的文件的名称。保存屏幕截图的目录能够在导入库时使用,也可使用Set Screenshot Directory关键字进行设置。若是未配置目录,则屏幕截图将保存到写入Robot Framework日志文件的同一目录中。

从SeleniumLibrary 1.8开始,若是filename包含marker {index},它将自动替换为惟一的运行索引,以防止文件被覆盖。索引从1开始,它们的表示方式可使用Python的格式字符串语法进行自定义。

返回建立的屏幕截图文件的绝对路径。

例子:

捕获页面截图  
文件应该存在 $ {} OUTPUTDIR /selenium-screenshot-1.png
$ {path} = 捕获页面截图
文件应该存在 $ {} OUTPUTDIR /selenium-screenshot-2.png
文件应该存在 $ {PATH}
捕获页面截图 custom_name.png
文件应该存在 $ {} OUTPUTDIR /custom_name.png
捕获页面截图 custom_with_index_ {索引} .PNG
文件应该存在 $ {} OUTPUTDIR /custom_with_index_1.png
捕获页面截图 formatted_index_ {指数:03}巴纽
文件应该存在 $ {} OUTPUTDIR /formatted_index_001.png
应选中复选框 定位器

locator选中/选中验证复选框。

有关定位器语法的详细信息,请参阅定位元素部分。

不该选中复选框 定位器

locator未选中/选中“ 验证”复选框。

有关定位器语法的详细信息,请参阅定位元素部分。

选择取消下次确认  

已过期。请直接使用Handle Alert

在SeleniumLibrary 3.0以前的版本中,须要在使用Confirm Action关键字以前单独设置警报处理方法。New Handle Alert关键字接受如何将警报做为普通参数处理的操做,应该使用它。

选择文件 locator, file_path

输入file_path到文件输入字段locator

此关键字最经常使用于将文件输入上载表单。指定的文件file_path必须在执行测试的机器上可用。

例:

选择文件 my_upload_field $ {} CURDIR /trades.csv
选择Ok On Next Confirmation  

已过期。请直接使用Handle Alert

在SeleniumLibrary 3.0以前的版本中,须要在使用Confirm Action关键字以前单独设置警报处理方法。New Handle Alert关键字接受如何将警报做为普通参数处理的操做,应该使用它。

清除元素文本 定位器

清除标识的文本输入元素的值locator

有关定位器语法的详细信息,请参阅定位元素部分。

单击按钮 定位器

点击按钮标识locator

有关定位器语法的详细信息,请参阅定位元素部分。当使用默认的定位战略,按钮使用搜索idnamevalue

单击元素 定位器

单击标识的元素locator

有关定位器语法的详细信息,请参阅定位元素部分。

单击坐标处的元素 定位器, xoffset, yoffset

点击元素locatorxoffset/yoffset

移动光标,从该点计算元素的中心和x / y坐标。

有关定位器语法的详细信息,请参阅定位元素部分。

单击图像 定位器

单击标识的图像locator

有关定位器语法的详细信息,请参阅定位元素部分。当使用默认的定位策略,图像是使用搜索idnamesrcalt

单击连接 定位器

单击标识的连接locator

有关定位器语法的详细信息,请参阅定位元素部分。当使用默认的定位策略,连接使用搜索idnamehref和连接文本。

关闭全部浏览器  

关闭全部打开的浏览器并重置浏览器缓存。

在此关键字以后,从Open Browser关键字返回的新索引将重置为1。

此关键字应在测试或套件拆解中使用,以确保全部浏览器都已关闭。

关闭浏览器  

关闭当前浏览器。

关闭窗口  

关闭当前打开的弹出窗口。

确认行动  

已过期。请改用Handle Alert

默认状况下,接受警报,但能够经过选择取消确认下一个确认选择肯定下一个确认关键字来更改此行为。New Handle Alert关键字接受如何将警报做为普通参数处理的操做,应该使用它。

建立Webdriver driver_name, alias = None, kwargs = {}, ** init_kwargs

建立Selenium WebDriver的实例。

Open Browser相似,但容许直接将参数传递给建立的WebDriver实例。仅当Open Browser提供的功能不足时,才应使用此关键字。

driver_name 必须是WebDriver实现名称,如Firefox,Chrome,即Opera,Opera,PhantomJS或Remote。

初始化的WebDriver可使用Python字典kwargs或使用关键字参数进行配置**init_kwargs。这些参数直接传递给WebDriver而不进行任何处理。有关支持的参数的详细信息,请参阅Selenium API文档

例子:

#在Firefox中使用代理      
$ {}代理= 评估 sys.modules中[ 'selenium.webdriver']。代理() sys,selenium.webdriver
$ {} proxy.http_proxy = 设置变量 本地主机:8888  
建立Webdriver 火狐 代理= $ {}代理  
#在PhantomJS上使用代理      
$ {service args} = 建立列表 --proxy = 192.168.132.104:8888  
建立Webdriver PhantomJS service_args = $ {service args}  

返回此浏览器实例的索引,稍后可使用该索引切换回它。索引从1开始,并在使用Close All Browsers关键字时重置为它。有关示例,请参阅Switch Browser

当前帧包含 text, loglevel = INFO

已过期。使用当前帧应该包含

当前框架应包含 text, loglevel = INFO

验证当前帧是否包含text

有关参数的说明,请参见页面应包含loglevel

在SeleniumLibrary 3.0以前,此关键字被命名为Current Frame Contains

当前框架不该包含 text, loglevel = INFO

验证当前帧是否包含text

有关参数的说明,请参见页面应包含loglevel

删除全部Cookie  

删除全部cookie。

删除Cookie 名称

删除cookie匹配name

若是找不到cookie,则没有任何反应。

解雇警报 接受=真

已过期。请改用Handle Alert

与其名称相反,此关键字默认接受警报(即按下Ok)。accept能够设置为false值以关闭警报(即按下Cancel)。

若是警报被接受,解雇或保持开放,则处理警报能够更好地支持控制。

双击元素 定位器

双击标识的元素locator

有关定位器语法的详细信息,请参阅定位元素部分。

拖放 定位器, 目标

drags元素由locatorinto target元素标识。

locator参数是拖动的元素的定位器和target是目标的定位器。有关定位器语法的详细信息,请参阅定位元素部分。

例:

拖放 CSS:DIV元素# CSS:div.target
经过偏移拖放 定位器, xoffset, yoffset

拖拽元素locatorxoffset/yoffset

有关定位器语法的详细信息,请参阅定位元素部分。

元素将被移动,xoffset而且yoffset每一个元素都是指定偏移量的负数或正数。

例:

经过偏移拖放 myElem 50 -35 #向右移动myElem 50px,向下移动35px
元素应该被禁用 定位器

验证标识的元素locator是否已禁用。

此关键字还会考虑禁用只读的元素。

有关定位器语法的详细信息,请参阅定位元素部分。

应该启用元素 定位器

验证locator已启用标识的元素。

此关键字还会考虑禁用只读的元素。

有关定位器语法的详细信息,请参阅定位元素部分。

元素应该集中 定位器

验证标识的元素locator是否为焦点。

有关定位器语法的详细信息,请参阅定位元素部分。

SeleniumLibrary 3.0中的新功能。

元素应该是可见的 locator, message =无

验证标识的元素locator是否可见。

这里,visible表示该元素在逻辑上可见,在当前浏览器视口中不是光学可见的。例如,携带的元素在display:none逻辑上不可见,所以在该元素上使用此关键字将失败。

有关定位器语法的详细信息,请参阅定位元素部分。

message参数可用于覆盖默认错误消息。

元素应该包含 locator, expected, message = None, ignore_case = False

验证该元素是否locator包含文本expected

有关定位器语法的详细信息,请参阅定位元素部分。

message参数可用于覆盖默认错误消息。

ignore_case参数能够设置为True比较不区分大小写,默认值为False。SeleniumLibrary 3.1中的新功能。

ignore_case SeleniumLibrary 3.1中的新参数。

若是要匹配确切的文本而不是子字符串,则应使用元素文本

元素不该该是可见的 locator, message =无

验证标识的元素locator是否不可见。

若是元素不存在则经过。有关可见性和支持的参数的详细信息,请参阅元素应该可见

元素不该该包含 locator, expected, message = None, ignore_case = False

验证该元素locator不包含文本expected

有关定位器语法的详细信息,请参阅定位元素部分。

message参数可用于覆盖默认错误消息。

ignore_case参数能够设置为True比较不区分大小写,默认值为False。

ignore_case SeleniumLibrary 3.1中的新参数。

元素文本应该是 locator, expected, message = None, ignore_case = False

验证该元素是否locator包含确切的文本expected

有关定位器语法的详细信息,请参阅定位元素部分。

message参数可用于覆盖默认错误消息。

ignore_case参数能够设置为True比较不区分大小写,默认值为False。

ignore_case SeleniumLibrary 3.1中的新参数。

若是须要子字符串匹配,则使用元素应包含

元素文本不该该 locator, not_expected, message = None, ignore_case = False

验证该元素locator不包含确切的文本not_expected

有关定位器语法的详细信息,请参阅定位元素部分。

message参数可用于覆盖默认错误消息。

ignore_case参数能够设置为True比较不区分大小写,默认值为False。

SeleniumLibrary 3.1.1中的新功能

执行异步Javascript *码

执行异步JavaScript代码。

Execute Javascript相似,不一样之处在于使用此关键字执行的脚本必须经过调用提供的回调明确表示它们已完成。此回调始终做为最后一个参数注入到执行的函数中。

脚本必须在脚本超时内完成,不然此关键字将失败。有关详细信息,请参阅超时部分。

例子:

执行异步JavaScript var callback = arguments [arguments.length - 1]; window.setTimeout(callback,2000);  
执行异步JavaScript $ {} CURDIR /async_js_to_execute.js  
$ {result} = 执行异步JavaScript  
... var callback = arguments [arguments.length - 1];  
... function answer(){callback(“text”);};  
... window.setTimeout(answer,2000);  
应该是平等的 $ {}结果 文本
执行Javascript *码

执行给定的JavaScript代码。

code能够包含多行代码,而且能够在测试数据中分红多个单元。在这种状况下,部件链接在一块儿而不添加空格。

若是code是现有文件的绝对路径,则将从该文件中读取要执行的JavaScript。正斜杠用做全部操做系统上的路径分隔符。

JavaScript在当前选定的框架或窗口的上下文中执行,做为匿名函数的主体。用window指应用程序的窗口,并document指当前帧或窗口,例如文档对象document.getElementById('example')

此关键字返回执行的JavaScript代码返回的任何内容。返回值将转换为适当的Python类型。

例子:

执行JavaScript window.myFunc('arg1','arg2')  
执行JavaScript $ {} CURDIR /js_to_execute.js  
$ {sum} = 执行JavaScript 返回1 + 1;
应该是平等的 $ {}总和 $ {2}
焦点 定位器

已过期。请改成使用Set Focus To Element

框架应该包含 locator, text, loglevel = INFO

验证由locatorcontains 标识的帧text

有关定位器语法的详细信息,请参阅定位元素部分。

有关参数的说明,请参见页面应包含loglevel

获取提醒消息 解雇=真

已过期。请改用Handle Alert

返回警报的消息。默认状况下解除警报(即按下Cancel),设置dismiss为false会使警报保持打开状态。没有支持接受警报(即按下Ok)。

若是警报被接受,解雇或保持开放,则处理警报能够更好地支持控制。

获取全部连接  

返回包含当前页面中找到的全部连接的ID的列表。

若是连接没有id,则列表中将出现一个空字符串。

获取Cookie 名称

name以对象的形式返回cookie的信息。

若是未找到cookie name,则关键字失败。cookie对象包含有关cookie的详细信息。对象中可用的属性记录在下表中。

属性 说明
名称 Cookie的名称。
cookie的价值。
路径 例如,表示URL路径/
Cookie可见的域。
安全 若是为true,则cookie仅用于HTTPS链接。
仅Http 若是为true,则没法经过JavaScript访问cookie。
到期 Python datetime对象,指示cookie什么时候到期。

有关cookie信息的详细信息,请参阅WebDriver规范。请注意,它expiry被指定为日期时间对象,而不是像UnixDepoch那样的秒,就像WebDriver自己那样。

例:

添加Cookie FOO 酒吧
$ {cookie} = 获取Cookie FOO
应该是平等的 $ {} cookie.name 酒吧
应该是平等的 $ {} cookie.value FOO
应该是真的 $ {cookie.expiry.year}> 2017  

SeleniumLibrary 3.0中的新功能。

获取Cookie值 名称

已过期。请改用Get Cookie

获取Cookies  

返回当前页面的全部cookie。

cookie信息以格式的单个字符串形式返回name1=value1; name2=value2; name3=value3。例如,它可用于记录目的,或在发送HTTP请求时用于标头。

获取元素属性 locator, attribute = None

返回attribute元素的值locator

有关定位器语法的详细信息,请参阅定位元素部分。

例:

$ {ID} = 获取元素属性 CSS:H1 ID

locator自SeleniumLibrary 3.0以来,不推荐将属性名称做为其中一部分传递。attribute应该使用显式参数。

获取元素计数 定位器

返回匹配的元素数locator

若是要声明匹配元素的数量,请使用Page should Contain Element with limitargument。关键字将始终返回一个整数。

例:

$ {count} = 获取元素计数 名称:div_name
应该是真的 $ {count}> 2  

SeleniumLibrary 3.0中的新功能。

获取元素大小 定位器

返回由标识的元素的宽度和高度locator

有关定位器语法的详细信息,请参阅定位元素部分。

宽度和高度都以整数形式返回。

例:

$ {}宽 $ {height} = 获取元素大小 CSS:DIV#集装箱
得到横向位置 定位器

返回由标识的元素的水平位置locator

有关定位器语法的详细信息,请参阅定位元素部分。

位置以页面左侧的像素为单位返回,为整数。

另请参阅获取垂直位置

获取列表项 locator, values = False

返回选择列表的全部标签或值locator

有关定位器语法的详细信息,请参阅定位元素部分。

默认状况下返回可见标签,但能够经过将values参数设置为true值来返回值(请参阅布尔参数)。

例:

$ {labels} = 获取列表项 个人列表  
$ {values} = 获取列表项 css:#example select 值=真

支持返回值是SeleniumLibrary 3.0中的新功能。

获取位置  

返回当前的浏览器URL。

获取地点  

返回并记录全部已知浏览器窗口的URL。

获取匹配的Xpath计数 xpath, return_str = True

已过期。请改用“ 获取元素计数”

获取选定的列表标签 定位器

从选择列表返回所选选项的标签locator

若是有多个选定选项,则返回第一个选项的标签。

有关定位器语法的详细信息,请参阅定位元素部分。

获取选定列表标签 定位器

从选择列表返回所选选项的标签locator

从SeleniumLibrary 3.0开始,若是没有选择,则返回一个空列表。在早期版本中,这会致使错误。

有关定位器语法的详细信息,请参阅定位元素部分。

获取选定的列表值 定位器

从选择列表返回所选选项的值locator

若是有多个选定选项,则返回第一个选项的值。

有关定位器语法的详细信息,请参阅定位元素部分。

获取选定的列表值 定位器

从选择列表返回所选选项的值locator

从SeleniumLibrary 3.0开始,若是没有选择,则返回一个空列表。在早期版本中,这会致使错误。

有关定位器语法的详细信息,请参阅定位元素部分。

获取Selenium Implicit Wait  

获取Selenium使用的隐式等待值。

该值做为人类可读的字符串返回1 second

有关详细信息,请参阅上面的隐式等待部分。

得到Selenium Speed  

获取每一个Selenium命令后等待的延迟。

该值做为人类可读的字符串返回1 second

有关详细信息,请参阅上面的Selenium Speed部分。

获取Selenium Timeout  

获取各类关键字使用的超时。

该值做为人类可读的字符串返回1 second

有关详细信息,请参阅上面的超时部分。

获取来源  

返回当前页面或框架的整个HTML源。

获取表格单元格 定位器, , , loglevel = INFO

返回表格单元格的内容。

使用locator参数找到该表,并使用row和找到它的单元格column。有关定位器语法的详细信息,请参阅定位元素部分。

行索引和列索引都从1开始,页眉和页脚行包含在计数中。能够经过使用负索引从末尾引用行和列,以便-1是最后一行/列,-2是最后一行,依此类推。

全部<th><td>表中的任何元素都被认为是细胞。

有关参数的说明,请参见页面应包含loglevel

获取文字 定位器

返回由标识的元素的文本值locator

有关定位器语法的详细信息,请参阅定位元素部分。

得到标题  

返回当前页面的标题。

得到价值 定位器

返回由标识的元素的value属性locator

有关定位器语法的详细信息,请参阅定位元素部分。

得到垂直位置 定位器

返回由标识的元素的垂直位置locator

有关定位器语法的详细信息,请参阅定位元素部分。

位置以页面顶部的像素为单位返回,做为整数。

另请参见获取水平位置

获取WebElement 定位器

返回与给定匹配的第一个WebElement locator

有关定位器语法的详细信息,请参阅定位元素部分。

获取WebElements 定位器

返回与之匹配的WebElement对象列表locator

有关定位器语法的详细信息,请参阅定位元素部分。

从SeleniumLibrary 3.0开始,若是没有匹配的元素,关键字将返回一个空列表。在之前的版本中,关键字在这种状况下失败。

获取窗口句柄  

将全部当前窗口句柄做为列表返回。

能够用做要使用选择窗口排除的窗口列表。

在SeleniumLibrary 3.0以前,此关键字被命名为List Windows

获取窗口标识符  

返回并记录全部已知浏览器窗口的id属性。

获取窗口名称  

返回并记录全部已知浏览器窗口的名称。

获取窗口位置  

返回当前窗口位置。

位置相对于屏幕的左上角。返回值是整数。另请参见设置窗口位置

例:

$ {X} $ {Y} = 获取窗口位置
获取窗口大小  

以整数形式返回当前窗口宽度和高度。

另请参见设置窗口大小

例:

$ {}宽 $ {高度} = 获取窗口大小
获取窗口标题  

返回并记录全部已知浏览器窗口的标题。

回去  

模拟用户单击其浏览器上的后退按钮。

网址

将活动的浏览器实例导航到提供的实例url

处理警报 action = ACCEPT, timeout = None

处理当前警报并返回其消息。

默认状况下,接受警报,但可使用action支持如下不区分大小写的值的参数来控制此警报:

  • ACCEPT:接受警报即按Ok。默认。
  • DISMISS:取消警报即按Cancel
  • LEAVE:保持警报打开。

timeout参数指定多久等待警报出现。若是未给出,则使用全局默认超时

例子:

处理警报     #接受提醒。
处理警报 行动= DISMISS   #解除警报。
处理警报 超时= 10秒   #使用自定义超时并接受警报。
处理警报 解雇 1分钟 #使用自定义超时和解除警报。
$ {message} = 处理警报   #接受提醒并获取其消息。
$ {message} = 处理警报 离开 #保持警报打开并获取其消息。

SeleniumLibrary 3.0中的新功能。

输入密码 定位器, 密码

将给定密码键入标识的文本字段locator

有关定位器语法的详细信息,请参阅定位元素部分。

输入文本相比的差别是此关键字不会在INFO级别上记录给定的密码。请注意,若是您使用关键字like

输入密码 password_field 密码

密码显示为普通关键字参数。避免这种状况的一种方法是使用像

输入密码 password_field $ {PASSWORD}

另请注意,SeleniumLibrary使用DEBUG级别记录与浏览器驱动程序的全部通讯,而且能够在那里看到实际密码。此外,Robot Framework使用TRACE级别记录全部参数。所以,若是不以任何格式记录密码,则必须使用低于INFO的级别执行测试。

输入文本 定位器, 文本

将给定的text文本字段标识为locator

若是您不但愿记录给定,请使用输入密码text

有关定位器语法的详细信息,请参阅定位元素部分。

将文本输入警报 text, action = ACCEPT, timeout = None

将给定类型text键入警报中的输入字段。

默认状况下接受警报,但可使用actionHandle Alert相同的方式控制该行为。

timeout指定等待警报显示的时间。若是未给出,则使用全局默认超时

SeleniumLibrary 3.0中的新功能。

将文本输入到提示中 文本

已过期。请改用输入文本到警报

将给定类型text键入警报中的输入字段。保持警报开放。

列表选择应该是 定位器, *预期

验证选择列表locator是否已expected选择选项。

能够将预期选项做为可见标签和值给出。从SeleniumLibrary 3.0开始,没法混合标签和值。未验证所选选项的顺序。

若是未给出预期选项,则验证列表没有选择。更明确的替代方案是使用列表应该没有选择

有关定位器语法的详细信息,请参阅定位元素部分。

例子:

列表选择应该是 性别  
列表选择应该是 利益 测试自动化 蟒蛇
列表应该没有选择 定位器

验证选择列表locator未选择任何选项。

有关定位器语法的详细信息,请参阅定位元素部分。

列出Windows  

已过期。请改用“ 获取窗口句柄”

位置应该是 网址

验证当前URL是否彻底正确url

位置应该包含 预期

验证当前URL是否包含expected

定位器应该匹配X次 locator, x, message = None, loglevel = INFO

不推荐使用,请使用Page should Contain Element with limitargument。

记录位置  

记录并返回当前URL。

日志源 记录等级= INFO

记录并返回当前页面或框架的HTML源。

loglevel参数定义所使用的日志级别。有效的日志级别WARNINFO(默认),DEBUGNONE(无日志记录)。

日志标题  

记录并返回当前页面的标题。

最大化浏览器窗口  

最大化当前浏览器窗口。

鼠标向下 定位器

模拟按下元素上的鼠标左键locator

有关定位器语法的详细信息,请参阅定位元素部分。

按下元素而不释放鼠标按钮。

另请参阅更具体的关键字鼠标按下图像鼠标按下连接

鼠标在图像上 定位器

在由标识的图像上模拟鼠标按下事件locator

有关定位器语法的详细信息,请参阅定位元素部分。当使用默认的定位策略,图像是使用搜索idnamesrcalt

鼠标按下连接 定位器

在由标识的连接上模拟鼠标按下事件locator

有关定位器语法的详细信息,请参阅定位元素部分。当使用默认的定位策略,连接使用搜索idnamehref和连接文本。

鼠标移出 定位器

模拟将鼠标移离元素locator

有关定位器语法的详细信息,请参阅定位元素部分。

鼠标移到 定位器

模拟将鼠标悬停在元素上locator

有关定位器语法的详细信息,请参阅定位元素部分。

鼠标向上 定位器

模拟释放元素上的鼠标左键locator

有关定位器语法的详细信息,请参阅定位元素部分。

打开浏览器 url, browser = firefox, alias = None, remote_url = Falsedesired_capabilities = None, ff_profile_dir = None

打开给定的新浏览器实例url

browser参数指定要使用的浏览器,和支持的浏览器列于下表中列出。浏览器名称不区分大小写,某些浏览器具备多个受支持的名称。

浏览器 名称(S)
火狐 firefox,ff
谷歌浏览器 googlechrome,chrome,gc
无头火狐 headlessfirefox
无头Chrome headlesschrome
IE浏览器 internetexplorer,即
边缘 边缘
苹果浏览器 苹果浏览器
歌剧 歌剧
Android的 安卓
苹果手机 苹果手机
PhantomJS phantomjs
的HtmlUnit 的HtmlUnit
使用Javascript的HTMLUnit htmlunitwithjs

为了可以实际使用这些浏览器之一,您须要提供匹配的Selenium浏览器驱动程序。有关详细信息,请参阅项目文档。Headless Firefox和Headless Chrome是SeleniumLibrary 3.1.0中的新增功能,须要Selenium 3.8.0或更新版本。

可选alias是为此浏览器实例指定的别名,它可用于在浏览器之间切换。切换的另外一种方法是使用此关键字返回的索引。这些索引从1开始,在打开新浏览器时递增,在调用Close All Browsers时重置为1 。有关更多信息和示例,请参阅切换浏览器

可选remote_urlSelenium Grid的URL 。

可选desired_capabilities用于配置,例如,在使用Sauce Labs时为浏览器或浏览器和操做系统配置日志首选项。所需的功能既能够做为Python字典提供,也能够做为字符串格式提供key1:value1,key2:value2Selenium文档列出了能够启用的功能。

可选的ff_profile_dir是,若是要覆盖默认的配置文件使用硒的路径Firefox的配置文件目录。请注意,在SeleniumLibrary 3.0以前,该库包含默认使用的本身的配置文件。

例子:

打开浏览器 http://example.com  
打开浏览器 http://example.com 火狐 别名=火狐
打开浏览器 http://example.com 边缘 remote_url = HTTP://127.0.0.1:4444 / WD /集线器

若是提供的配置选项不够,则可使用Create Webdriver进一步自定义浏览器初始化。

desired_capabilities在本地浏览器中应用参数是SeleniumLibrary 3.1中的新功能。

打开上下文菜单 定位器

在标识的元素上打开上下文菜单locator

页面应该包含 text, loglevel = INFO

验证当前页面是否包含text

若是此关键字失败,它将使用使用optional loglevel参数指定的日志级别自动记录页面源。有效的日志级别DEBUGINFO(默认),WARNNONE。若是日志级别NONE等于或低于当前活动日志级别,则不会记录源。

页面应包含按钮 locator, message = None, loglevel = INFO

locator从当前页面找到验证按钮。

有关和参数的说明,请参见页面应包含元素messageloglevel

有关定位器语法的详细信息,请参阅定位元素部分。当使用默认的定位战略,按钮使用搜索idnamevalue

页面应包含复选框 locator, message = None, loglevel = INFO

locator从当前页面找到“ 验证”复选框。

有关和参数的说明,请参见页面应包含元素messageloglevel

有关定位器语法的详细信息,请参阅定位元素部分。

页面应包含元素 locator, message = None, loglevel = INFO, limit = None

验证locator在当前页面上找到该元素。

有关定位器语法的详细信息,请参阅定位元素部分。

message参数可用于覆盖默认错误消息。

limit参数可用于定义页面应包含的元素数量。当limitNone(默认)页面能够包含一个或多个元素。当limit是一个数字时,页面必须包含相同数量的元素。

有关参数的说明,请参见页面应包含loglevel

示例假定定位器与两个元素匹配。

页面应包含元素 div_name 极限= 1 #关键字失败。
页面应包含元素 div_name 极限= 2 #关键字传递。
页面应包含元素 div_name 极限=无 #None被认为是一个或多个。
页面应包含元素 div_name   #与上述相同。

这个limit论点在SeleniumLibrary 3.0中是新的。

页面应包含图像 locator, message = None, loglevel = INFO

验证locator从当前页面找到的标识图像。

有关定位器语法的详细信息,请参阅定位元素部分。当使用默认的定位策略,图像是使用搜索idnamesrcalt

有关和参数的说明,请参见页面应包含元素messageloglevel

页面应包含连接 locator, message = None, loglevel = INFO

验证locator从当前页面找到的标识连接。

有关定位器语法的详细信息,请参阅定位元素部分。当使用默认的定位策略,连接使用搜索idnamehref和连接文本。

有关和参数的说明,请参见页面应包含元素messageloglevel

页面应包含列表 locator, message = None, loglevel = INFO

验证locator从当前页面找到选择列表。

有关和参数的说明,请参见页面应包含元素messageloglevel

有关定位器语法的详细信息,请参阅定位元素部分。

页面应包含单选按钮 locator, message = None, loglevel = INFO

locator从当前页面找到验证单选按钮。

有关和参数的说明,请参见页面应包含元素messageloglevel

有关定位器语法的详细信息,请参阅定位元素部分。当使用默认的定位策略,单选按钮使用搜索idnamevalue

页面应包含文本字段 locator, message = None, loglevel = INFO

验证locator从当前页面找到的文本字段。

有关和参数的说明,请参见页面应包含元素messageloglevel

有关定位器语法的详细信息,请参阅定位元素部分。

页面不该该包含 text, loglevel = INFO

验证当前页面不包含text

有关参数的说明,请参见页面应包含loglevel

页面不该包含按钮 locator, message = None, loglevel = INFO

locator从当前页面找不到“ 验证”按钮。

有关和参数的说明,请参见页面应包含元素messageloglevel

有关定位器语法的详细信息,请参阅定位元素部分。当使用默认的定位战略,按钮使用搜索idnamevalue

页面不该包含复选框 locator, message = None, loglevel = INFO

locator从当前页面找不到“ 验证”复选框。

有关和参数的说明,请参见页面应包含元素messageloglevel

有关定位器语法的详细信息,请参阅定位元素部分。

页面不该包含元素 locator, message = None, loglevel = INFO

验证locator在当前页面上找到该元素。

有关定位器语法的详细信息,请参阅定位元素部分。

有关和参数的说明,请参见页面应包含messageloglevel

页面不该包含图像 locator, message = None, loglevel = INFO

验证locator从当前页面找到的标识图像。

有关定位器语法的详细信息,请参阅定位元素部分。当使用默认的定位策略,图像是使用搜索idnamesrcalt

有关和参数的说明,请参见页面应包含元素messageloglevel

页面不该包含连接 locator, message = None, loglevel = INFO

验证locator在当前页面中找不到标识的连接。

有关定位器语法的详细信息,请参阅定位元素部分。当使用默认的定位策略,连接使用搜索idnamehref和连接文本。

有关和参数的说明,请参见页面应包含元素messageloglevel

页面不该包含列表 locator, message = None, loglevel = INFO

验证locator当前页面中未找到选择列表。

有关和参数的说明,请参见页面应包含元素messageloglevel

有关定位器语法的详细信息,请参阅定位元素部分。

页面不该包含单选按钮 locator, message = None, loglevel = INFO

locator从当前页面找不到验证单选按钮。

有关和参数的说明,请参见页面应包含元素messageloglevel

有关定位器语法的详细信息,请参阅定位元素部分。当使用默认的定位策略,单选按钮使用搜索idnamevalue

页面不该包含文本字段 locator, message = None, loglevel = INFO

验证locator当前页面中未找到文本字段。

有关和参数的说明,请参见页面应包含元素messageloglevel

有关定位器语法的详细信息,请参阅定位元素部分。

按键 定位器, 关键

模拟用户按下标识的元素上的键locator

有关定位器语法的详细信息,请参阅定位元素部分。

key 能够是单个字符,字符串,也能够是'\\'键引导的数字ASCII代码。

例子:

按键 文本域 q  
按键 文本域 ABCDE  
按键 login_button须要 \\ 13 #enter key的ASCII码
单选按钮应设置为 group_name, value

验证单选按钮组group_name设置为value

group_namename单选按钮组的。

不该选择单选按钮 团队名字

验证单选按钮组group_name没有选择。

group_namename单选按钮组的。

注册关键字以在失败时运行 关键词

设置SeleniumLibrary关键字失败时要执行的关键字。

keyword是SeleniumLibrary关键字失败时将执行的关键字的名称。可使用任何可用的关键字,包括用户关键字或其余库中的关键字,但关键字不能带任何参数。

导入库时设置要使用的初始关键字,默认状况下使用的关键字是Capture Page Screenshot。在出现故障时拍摄屏幕截图是一个很是有用的功能,但请注意它能够减慢执行速度。

可使用字符串NOTHINGNONE不区分大小写,以及Python None来彻底禁用此功能。

None若是先前已禁用此功能,则此关键字将返回先前注册的失败关键字或Python的名称。能够始终使用返回值来稍后恢复原始值。

例:

注册关键字以在失败时运行 日志源  
$ {previous kw} = 注册关键字以在失败时运行 没有
注册关键字以在失败时运行 $ {previous kw}  

SeleniumLibrary 3.0的变化:

  • 可使用字符串NONE或Python None来禁用该功能。
  • None在先前禁用该功能时返回Python 。在之前的版本中No Keyword,返回了特殊值,它没法用于恢复原始状态。
从新加载页面  

模拟用户从新加载页面。

删除位置策略 STRATEGY_NAME

删除之前添加的自定义位置策略。

有关如何建立和使用自定义策略的信息,请参阅自定义定位器

从列表中选择所有 定位器

从多选列表中选择全部选项locator

有关定位器语法的详细信息,请参阅定位元素部分。

选择复选框 定位器

选择标识的复选框locator

若是已选中复选框则不执行任何操做

有关定位器语法的详细信息,请参阅定位元素部分。

选择框架 定位器

设置由locator当前帧标识的帧。

有关定位器语法的详细信息,请参阅定位元素部分。

适用于框架和iframe。使用取消选择框取消帧选择并返回主框架。

例:

选择框架 顶部框架 #选择ID为“top-frame”的框架
单击连接 #单击所选框架中的连接“示例”
取消选择框架   #回到主框架。
选择框架 // IFRAME [@名称= 'XXX'] #使用xpath选择框架
从列表中选择 定位器, *选项

已过期。使用从标签/值/索引按列表选择

此关键字根据标签或值选择选项,这使得它很是复杂和缓慢。它已经在SeleniumLibrary 3.0被弃用,而专用的关键字从列表中选择按标签从列表中选择按值,并从列表中选择按索引应改成使用。

从索引列表中选择 定位器, *索引

选择从选择列表中选择locatorindexes

列表选项的索引从0开始。

若是为单选列表指定了多个选项,则将选择最后一个值。使用多选列表,将选择全部指定的选项,但不会清除可能的旧选择。

有关定位器语法的详细信息,请参阅定位元素部分。

从标签列表中选择 定位器, *标签

选择从选择列表中选择locatorlabels

若是为单选列表指定了多个选项,则将选择最后一个值。使用多选列表,将选择全部指定的选项,但不会清除可能的旧选择。

有关定位器语法的详细信息,请参阅定位元素部分。

从按值列出中选择 定位器, *值

选择从选择列表中选择locatorvalues

若是为单选列表指定了多个选项,则将选择最后一个值。使用多选列表,将选择全部指定的选项,但不会清除可能的旧选择。

有关定位器语法的详细信息,请参阅定位元素部分。

选择单选按钮 group_name, value

将单选按钮组设置group_namevalue

要选择的单选按钮由两个参数定位:

  • group_name 是单选按钮组的名称。
  • valueidvalue实际单选按钮的属性。

例子:

选择单选按钮 尺寸 XL
选择单选按钮 联系 电子邮件
选择窗口 定位符= MAIN

选择浏览器窗口匹配locator

若是找到该窗口,则全部后续命令都将使用所选窗口,直到再次使用此关键字。若是找不到该窗口,则此关键字将失败。返回前一个窗口句柄,可用于稍后返回。

请注意,在此上下文窗口中表示在现有窗口上执行某些操做时打开的弹出窗口。没法选择使用Open Browser打开的窗口,必须使用Switch Browser。另请注意,应使用Handle Alert或其余与警报相关的关键字处理警报

locator能够采用不一样的策略有点相似,看成为被指定的定位元件上的网页。

  • 默认状况下,locator它与窗口句柄,名称,标题和URL匹配。按顺序进行匹配,并选择第一个匹配窗口。
  • locator能够指定使用格式的明确战略strategy:value(推荐)或strategy=value。支持的策略是nametitle而且url分别使用名称,标题和URL匹配窗口。另外,default能够用于明确使用上面解释的默认策略。
  • 若是locatorNEW(不区分大小写),则选择最新打开的窗口。若是它与当前窗口相同则是错误。
  • 若是locatorMAIN(默认状况下不区分大小写),则选择主窗口。
  • 若是locatorCURRENT(不区分大小写),则不执行任何操做。这实际上只返回当前窗口句柄。
  • 若是locator不是字符串,则应该是要排除的窗口句柄列表。在执行打开新窗口的操做以前,能够从Get Window Handles获取这样的排除窗口列表。

例:

单击连接 popup1   #打开新窗口
选择窗口   #使用默认策略选择窗口
标题应该是 弹出1    
单击按钮 popup2   #打开另外一个窗口
$ {handle} = 选择窗口 #选择最新打开的窗口
标题应该是 弹出2    
选择窗口 $ {}手柄   #使用句柄选择窗口
标题应该是 弹出1    
选择窗口 主要   #选择主窗口
标题应该是 主要    
$ {excludes} = 获取窗口句柄   #获取当前窗口列表
单击连接 popup3   #再打开一个窗口
选择窗口 $ {}排除   #使用排除选择窗口
标题应该是 弹出3    

注意:

  • strategy:value只有SeleniumLibrary 3.0及更高版本支持该语法。
  • 早期版本支持别名Nonenull用于选择主窗口的空字符串和self用于选择当前窗口的别名。这些别名在SeleniumLibrary 3.0中已弃用。
  • 在SeleniumLibrary 3.0按名称匹配窗口以前,标题和URL不区分大小写。
设置浏览器隐式等待

设置Selenium使用的隐式等待值。

Set Selenium Implicit Wait相同,但仅影响当前浏览器。

将焦点设置为元素 定位器

将焦点设置为标识的元素locator

有关定位器语法的详细信息,请参阅定位元素部分。

在SeleniumLibrary 3.0以前,这个关键字被命名为Focus

设置截屏目录 path, persist = DEPRECATED

设置捕获的屏幕截图的目录。

pathargument指定应写入屏幕截图的目录的绝对路径。若是该目录不存在,则将建立该目录。导入库时也能够设置目录。若是未在任何位置配置,则屏幕截图将保存到写入Robot Framework日志文件的同一目录中。

persist 参数已弃用且无效。

返回前一个值,能够在之后根据须要恢复原始值。

persist在SeleniumLibrary 3.0中,弃用并返回先前的值是新的。

设置Selenium Implicit Wait

设置Selenium使用的隐式等待值。

该值能够做为被认为是秒的数字给出,或者做为人类可读的字符串给出1 second。返回前一个值,能够在之后根据须要恢复原始值。

此关键字设置全部已打开浏览器的隐式等待。使用Set Browser Implicit Wait将其设置为仅当前浏览器。

有关详细信息,请参阅上面的隐式等待部分。

例:

$ {orig wait} = 设置Selenium Implicit Wait 10秒
执行缓慢的AJAX调用    
设置Selenium Implicit Wait $ {orig等待}  
设置Selenium Speed

设置每一个Selenium命令后等待的延迟。

该值能够做为被认为是秒的数字给出,或者做为人类可读的字符串给出1 second。返回前一个值,能够在之后根据须要恢复原始值。

有关详细信息,请参阅上面的Selenium Speed部分。

例:

设置Selenium Speed 0.5秒
设置Selenium Timeout

设置各类关键字使用的超时。

该值能够做为被认为是秒的数字给出,或者做为人类可读的字符串给出1 second。返回前一个值,能够在之后根据须要恢复原始值。

有关详细信息,请参阅上面的超时部分。

例:

$ {orig timeout} = 设置Selenium Timeout 15秒
打开加载缓慢的页面    
设置Selenium Timeout $ {orig timeout}  
设置窗口位置 x, y

使用xy坐标设置窗口位置。

该位置相对于屏幕的左上角,但某些浏览器排除了操做系统从计算中设置的可能任务栏。所以,实际位置可能因不一样浏览器而不一样。

可使用包含数字的字符串或使用实际数字来给出值。另请参见获取窗口位置

例:

设置窗口位置 100 200
设置窗口大小 宽度, 高度

将当前窗口大小设置为给定widthheight

可使用包含数字的字符串或使用实际数字来给出值。另请参阅获取窗口大小

浏览器限制了它们的设置。尝试将它们设置得更小将致使实际大小大于请求的大小。

例:

设置窗口大小 800 600
模拟 定位器, 事件

已过期。请改用模拟事件

模拟事件 定位器, 事件

模拟event由标识的元素locator

若是element具备OnEvent须要显式调用的处理程序,则此关键字颇有用。

有关定位器语法的详细信息,请参阅定位元素部分。

在SeleniumLibrary 3.0以前,这个关键字被命名为Simulate

提交表格 定位器=无

提交由...标识的表格locator

若是locator没有给出,则提交页面上的第一个表单。

有关定位器语法的详细信息,请参阅定位元素部分。

切换浏览器 index_or_alias

在活动浏览器之间切换index_or_alias

Open Browser关键字返回索引,而且能够显式地为其指定别名。指数从1开始。

例:

打开浏览器 http://google.com FF  
位置应该是 http://google.com    
打开浏览器 http://yahoo.com 别名=第二
位置应该是 http://yahoo.com    
切换浏览器 1 #index  
页面应该包含 我感受我是幸运的    
切换浏览器 第二 #alias  
页面应该包含 更多雅虎!    
关闭全部浏览器      

上面的示例预计在打开第一个浏览器时没有其余打开的浏览器,由于它1在之后切换到它时使用了索引。若是您不肯定,能够将索引存储到变量中,以下所示。

$ {index} = 打开浏览器 http://google.com
# 作一点事 ...    
切换浏览器 $ {}指数  
表格单元格应该包含 locator, row, column, expected, loglevel = INFO

验证表格单元格包含文本expected

有关已接受参数的说明,请参阅此关键字在内部使用的获取表单元

表列应包含 locator, column, expected, loglevel = INFO

验证表列包含文本expected

该表使用locator参数及其找到的列来定位column。有关定位器语法的详细信息,请参阅定位元素部分。

列索引从1开始。可使用负索引从末尾引用列,以便-1是最后一列,-2是最后一列,依此类推。

若是表包含跨多个列的单元格,则这些合并的单元格将计为单个列。

有关参数的说明,请参见Page Should Contain Elementloglevel

表页脚应该包含 locator, expected, loglevel = INFO

验证表格页脚包含文本expected

<td>元素内的任何元素都<tfoot>被视为页脚的一部分。

该表使用locator参数定位。有关定位器语法的详细信息,请参阅定位元素部分。

有关参数的说明,请参见Page Should Contain Elementloglevel

表头应该包含 locator, expected, loglevel = INFO

验证表头包含文本expected

<th>表中任何位置的任何元素都被视为标题的一部分。

该表使用locator参数定位。有关定位器语法的详细信息,请参阅定位元素部分。

有关参数的说明,请参见Page Should Contain Elementloglevel

表行应包含 locator, row, expected, loglevel = INFO

验证表行包含文本expected

该表使用locator参数及其找到的列来定位column。有关定位器语法的详细信息,请参阅定位元素部分。

行索引从1开始。可使用负索引从末尾引用行,以便-1是最后一行,-2是最后一行,依此类推。

若是表包含跨越多行的单元格,则仅对这些合并单元格的最上一行进行匹配。

有关参数的说明,请参见Page Should Contain Elementloglevel

表应该包含 locator, expected, loglevel = INFO

验证表包含文本expected

该表使用locator参数定位。有关定位器语法的详细信息,请参阅定位元素部分。

有关参数的说明,请参见Page Should Contain Elementloglevel

Textarea应该包含 locator, expected, message =无

验证文本区域locator包含文本expected

message 可用于覆盖默认错误消息。

有关定位器语法的详细信息,请参阅定位元素部分。

Textarea值应该是 locator, expected, message =无

验证文本区域locator是否具备彻底文本expected

message 可用于覆盖默认错误消息。

有关定位器语法的详细信息,请参阅定位元素部分。

Textfield应该包含 locator, expected, message =无

验证文本字段locator包含文本expected

message 可用于覆盖默认错误消息。

有关定位器语法的详细信息,请参阅定位元素部分。

应该是Textfield值 locator, expected, message =无

验证文本字段locator具备彻底文本expected

message 可用于覆盖默认错误消息。

有关定位器语法的详细信息,请参阅定位元素部分。

标题应该是 标题, 消息=无

验证当前页面标题是否等于title

message参数可用于覆盖默认错误消息。

message 参数是SeleniumLibrary 3.1中的新内容。

从列表中取消选择所有 定位器

取消选择多选列表中的全部选项locator

有关定位器语法的详细信息,请参阅定位元素部分。

SeleniumLibrary 3.0中的新功能。

取消选中复选框 定位器

删除选中的复选框locator

若是未选中该复选框,则不执行任何操做

有关定位器语法的详细信息,请参阅定位元素部分。

取消选择框架  

将主框架设置为当前框架。

实际上取消了以前的Select Frame调用。

从列表中取消选择 定位器, *项目

已过期。使用取消选择标签/值/索引列表

此关键字根据标签或值取消选择选项,这使得它很是复杂和缓慢。它已经在SeleniumLibrary 3.0被弃用,专用关键字取消选择从列表按标签取消选择从列表按值取消选择从列表按索引应改成使用。

从索引列表中取消选择 定位器, *索引

从选择列表中取消选择选项locatorindexes

列表选项的索引从0开始。此关键字仅适用于多选列表。

有关定位器语法的详细信息,请参阅定位元素部分。

从标签列表中取消选择 定位器, *标签

从选择列表中取消选择选项locatorlabels

此关键字仅适用于多选列表。

有关定位器语法的详细信息,请参阅定位元素部分。

从值列表中取消选择 定位器, *值

从选择列表中取消选择选项locatorvalues

此关键字仅适用于多选列表。

有关定位器语法的详细信息,请参阅定位元素部分。

等待条件 condition, timeout = None, error = None

等待直到condition真或timeout过时。

条件能够是任意JavaScript表达式,但必须返回要评估的值。有关访问页面上的内容的信息,请参阅执行JavaScript

若是超时在条件变为真以前到期,则失败。有关使用超时及其默认值的详细信息,请参阅超时部分。

error 可用于覆盖默认错误消息。

例子:

等待条件 return document.title ==“新标题”
等待条件 return jQuery.active == 0
等待条件 style = document.querySelector('h1')。style; return style.background ==“red”&& style.color ==“white”
等到元素包含 locator, text, timeout = None, error = None

等到元素locator包含text

若是timeout在文本出现以前过时则失败。有关使用超时及其默认值的详细信息,请参阅“ 超时”部分,有关定位器语法的详细信息,请参阅“ 定位元素”部分。

error 可用于覆盖默认错误消息。

等到元素不包含 locator, text, timeout = None, error = None

等到元素locator不包含text

若是timeout在文本消失以前过时则失败。有关使用超时及其默认值的详细信息,请参阅“ 超时”部分,有关定位器语法的详细信息,请参阅“ 定位元素”部分。

error 可用于覆盖默认错误消息。

等到元素启用 locator, timeout =无, 错误=无

等待元素locator启用。

若是元素未禁用或只读,则认为元素已启用。

若是timeout在启用元素以前到期,则失败。有关使用超时及其默认值的详细信息,请参阅“ 超时”部分,有关定位器语法的详细信息,请参阅“ 定位元素”部分。

error 可用于覆盖默认错误消息。

考虑要禁用的只读元素是SeleniumLibrary 3.0中的新功能。

等到元素不可见 locator, timeout =无, 错误=无

等到元素locator不可见。

若是timeout在元素不可见以前到期,则失败。有关使用超时及其默认值的详细信息,请参阅“ 超时”部分,有关定位器语法的详细信息,请参阅“ 定位元素”部分。

error 可用于覆盖默认错误消息。

等到元素可见 locator, timeout =无, 错误=无

等到元素locator可见。

若是timeout在元素可见以前到期,则失败。有关使用超时及其默认值的详细信息,请参阅“ 超时”部分,有关定位器语法的详细信息,请参阅“ 定位元素”部分。

error 可用于覆盖默认错误消息。

等到页面包含 text, timeout = None, error = None

等到text当前页面出现。

若是timeout在文本出现以前过时则失败。有关使用超时及其默认值的详细信息,请参阅超时部分。

error 可用于覆盖默认错误消息。

等到页面包含元素 locator, timeout =无, 错误=无

等到元素locator出如今当前页面上。

若是timeout在元素出现以前到期,则失败。有关使用超时及其默认值的详细信息,请参阅“ 超时”部分,有关定位器语法的详细信息,请参阅“ 定位元素”部分。

error 可用于覆盖默认错误消息。

等到页面不包含 text, timeout = None, error = None

等待直到text从当前页面消失。

若是timeout在文本消失以前过时则失败。有关使用超时及其默认值的详细信息,请参阅超时部分。

error 可用于覆盖默认错误消息。

等到页面不包含元素 locator, timeout =无, 错误=无

等待元素locator从当前页面消失。

若是timeout在元素消失以前过时则失败。有关使用超时及其默认值的详细信息,请参阅“ 超时”部分,有关定位器语法的详细信息,请参阅“ 定位元素”部分。

error 可用于覆盖默认错误消息。

Xpath应该匹配X次 xpath, x, message = None, loglevel = INFO

不推荐使用,请使用Page should Contain Element with limitargument。

相关文章
相关标签/搜索