GetValue关键字用于获取某个元素标签对应的value属性,该关键字接收[locator]这一个参数,locator可以通过id,name,xpath等都可以进行定位。
${value}GetValueid=signin
log${value}
CloseBrowser
运行结果如下:
Startingtest:RobotFrameworkTest1.TestSuite6.TestCase0012
2018072813:35:00.116:INFO:get_attributevalue
Endingtest:RobotFrameworkTest1.TestSuite6.TestCase0012
GetWebelements关键字用来获取所有获得的WebElement对象的列表,该关键字接收[locator]这一个参数,locator可以通过id,name,xpath等都可以进行定位。
GetWebelement关键字和GetWebelements很类似,只不过GetWebelement只会返回匹配到的第一个WebElement对象。
示例1:访问百度首页,然后根据locator为name=tj_trnews来获取到可以匹配到的所有的WebElement对象的列表
${ement}GetWebelementsname=tj_trnews
log${ement}
Startingtest:RobotFrameworkTest1.TestSuite6.TestCase0013
2018072814:54:50.182:INFO:${ement}=[
2018072814:54:50.183:INFO:[
Endingtest:RobotFrameworkTest1.TestSuite6.TestCase0013
示例2:访问百度首页,然后根据locator为name=tj_trnews来获取匹配到的第一个WebElement对象
${ement}GetWebelementname=tj_trnews
Startingtest:RobotFrameworkTest1.TestSuite6.TestCase0014
2018072815:02:07.093:INFO:${ement}=
2018072815:02:07.094:INFO:
Endingtest:RobotFrameworkTest1.TestSuite6.TestCase0014
GetWindowTitles用来获取当前已经打开的浏览器窗口的所有Title。该关键字接收不需要接收任何的参数。
示例1:这里我们打开百度的首页,然后点击首页右上角的”新闻”链接按钮,挑战到百度新闻页面,最后获取该窗口下的所有Title。
ClickLink新闻
${title1}GetWindowTitles
log${title1}
CloseAllBrowsers
运行结果如下:如下图所示。
GoBack和GoTo关键字分别用来模拟对浏览器进行后退和前进的操作。GoBack关键字不需要接收任何的参数,GoTo关键字接收一个[url]参数。url是一个需要跳转到的地址。
示例1:这里我们首先访问百度首页,之后点击”新闻”链接,跳转到百度新闻页面,然后我们执行GoBack回退到百度首页,最后使用GoTo跳转到博客园首页,在每一个操作中,我们都记录了浏览器的窗口标题。
GoBack
${title2}GetWindowTitles
log${title2}
${title3}GetWindowTitles
log${title3}
Startingtest:RobotFrameworkTest1.TestSuite6.TestCase0016
2018072815:26:24.906:INFO:Clickinglink'新闻'.
2018072815:26:27.947:INFO:
Altogether1item.
1:百度新闻——全球最大的中文新闻平台
2018072815:26:27.948:INFO:${title1}=[u'\u767e\u5ea6\u65b0\u95fb\u2014\u2014\u5168\u7403\u6700\u5927\u7684\u4e2d\u6587\u65b0\u95fb\u5e73\u53f0']
2018072815:26:27.949:INFO:[u'\u767e\u5ea6\u65b0\u95fb\u2014\u2014\u5168\u7403\u6700\u5927\u7684\u4e2d\u6587\u65b0\u95fb\u5e73\u53f0']
2018072815:26:28.239:INFO:
1:百度一下,你就知道
2018072815:26:28.240:INFO:${title2}=[u'\u767e\u5ea6\u4e00\u4e0b\uff0c\u4f60\u5c31\u77e5\u9053']
2018072815:26:28.242:INFO:[u'\u767e\u5ea6\u4e00\u4e0b\uff0c\u4f60\u5c31\u77e5\u9053']
2018072815:26:31.021:INFO:
1:博客园-开发者的网上家园
2018072815:26:31.021:INFO:${title3}=[u'\u535a\u5ba2\u56ed-\u5f00\u53d1\u8005\u7684\u7f51\u4e0a\u5bb6\u56ed']
2018072815:26:31.022:INFO:[u'\u535a\u5ba2\u56ed-\u5f00\u53d1\u8005\u7684\u7f51\u4e0a\u5bb6\u56ed']
Endingtest:RobotFrameworkTest1.TestSuite6.TestCase0016
从运行的日志可以很清楚的看到GoBack和GoTo关键字在使用时起到的效果。
GetListItems关键字用来获取获取页面中一个下拉列表中所有的下拉选项,关键字接收[locator]一个参数,locator可以通过id或者name等来进行元素定位。
示例1:我们以访问百度贴吧中如下的下拉框为例来对该关键字的使用进行说明,如下图所示。
@{Items}GetListItemsname=sm
Startingtest:RobotFrameworkTest1.TestSuite6.TestCase0023
2018072823:27:24.714:INFO:get_attributemultiple
Endingtest:RobotFrameworkTest1.TestSuite6.TestCase0023
GetSelectedListValue关键字用于获取页面中选中的一个下拉列表的Value值,关键字接收[locator]一个参数,locator可以通过id或者name等来进行元素定位。
示例1:这里我们依然以访问百度贴吧中如下的下拉框为例来对该关键字的使用进行说明,如下图所示
${Value}GetSelectedListValuename=sm
log${Value}
Startingtest:RobotFrameworkTest1.TestSuite6.TestCase0025
2018072823:55:05.545:INFO:get_attributemultiple
2018072823:55:05.599:INFO:get_attributevalue
2018072823:55:05.609:INFO:${Value}=1
2018072823:55:05.610:INFO:1
Endingtest:RobotFrameworkTest1.TestSuite6.TestCase0025
从运行结果看,刚好与我们通过浏览器的开发工具看到的value值完全一致,如下图所示。
SelectFromList关键字用来模拟从指定的下拉列表中选择指定的下拉列表选项,该关键字接收[locator|*items]多个参数,locator可以通过id,name来进行元素的定位,当列表中传入多个值时,默认选择最后一条,如果传入的是一个空列表,那么会默认选择这个列表中的所有值。
这个选项对应的value为2,所以我们在关键字的参数中传入的参数为2,如下图所示。
SelectFromListname=sm2
sleep5
Startingtest:RobotFrameworkTest1.TestSuite6.TestCase0031
2018072909:53:49.543:INFO:Selectingoption(s)'2'fromlist'name=sm'.
2018072909:53:49.582:INFO:get_attributemultiple
2018072909:53:54.675:INFO:Slept5seconds
Endingtest:RobotFrameworkTest1.TestSuite6.TestCase0031