设置
代码语言:javascript复制程序库 Selenium2Library
变量文件 var.py
变量
代码语言:javascript复制@{words} 软件测试 大数据 云计算 C Java Python 编译原理 数据库 软件工程
用例
访问百度
代码语言:javascript复制 open browser https://www.baidu.com firefox
${SearchWords} Set Variable 软件测试
Input Text name=wd ${SearchWords}
Click Button id=su
Wait Until Element Is Visible class=n 20
${title} Get Title
Should be Equal ${title} ${SearchWords}_百度搜索
Close Browser
切换iframe
代码语言:javascript复制 open browser http://www.3testing.com/ firefox
Select Frame xpath=/html/body/iframe[1]
Click link id=introduce
Page Should Contain 顾翔
Close Browser
切换windows
代码语言:javascript复制 open browser https://www.baidu.com firefox
Click link name=tj_briicon
${handles} Get Window Handles
Switch Window ${handles[0]}
Close Window
Switch Window ${handles[1]}
Wait Until Element Is Visible xpath=//*[@id="content"]/h3[1] 20
Page Should Contain 文心一言
Close Window
Close Browser
移动鼠标
代码语言:javascript复制 open browser https://www.baidu.com firefox
${SearchWords} Set Variable 软件测试
Input Text name=wd ${SearchWords}
Click Button id=su
Wait Until Element Is Visible class=n 20
${title} Get Title
Should be Equal ${title} ${SearchWords}_百度搜索
Mouse Over name=tj_settingicon
Click link class=last
Page Should Contain 隐私设置
Close Browser
键盘操作
代码语言:javascript复制 open browser https://www.baidu.com firefox
${SearchWords} Set Variable 软件测试
Input Text name=wd ${SearchWords}
Press Key id=su Keys.ENTER
Wait Until Element Is Visible class=n 20
${title} Get Title
Should be Equal ${title} ${SearchWords}_百度搜索
${SearchWords} Set Variable 大数据
Input Text name=wd ${SearchWords}
Press Key id=su \10
Wait Until Page Contains ${SearchWords} 20
${title} Get Title
Should be Equal ${title} ${SearchWords}_百度搜索
Close Browser
电子商务网站操作
代码语言:javascript复制 open browser http://127.0.0.1:8000 firefox
Input Text name=username cindy
Input Text name=password 123456
Submit Form name=myForm
Wait Until Element Is Visible name=good 20
${title} Get Title
Should be Equal ${title} 电子商务系统
Close Browser
cookies操作
代码语言:javascript复制 open browser http://127.0.0.1:8000/ firefox
Input Text name=username cindy
Input Text name=password 123456
Submit Form name=myForm
Wait Until Element Is Visible name=good 20
${title} Get Title
Should be Equal ${title} 电子商务系统
Add Cookie 1 1
Add Cookie 2 2
go to http://127.0.0.1:8000/goods_view/
Page Should Contain 查看购物车2
click link /view_chart/
Element Should Be Visible xpath=/html/body/div[2]/div[1]/div/table/tbody/tr[1]/td[4]/form
Close Browser
单复选框
代码语言:javascript复制 open browser http://127.0.0.1:8080/sec/33/index.html firefox
Click Element xpath=//input[@type='radio' and @value='Traditional_Chinese']
Element Should Be Focused xpath=//input[@type='radio' and @value='Traditional_Chinese']
${condition} Get Element Attribute id=c1 @checked
Run Keyword If '${condition}' == 'true' Log 复选框已被选中
... ELSE Click Element id=c1
Checkbox Should Be Selected id=c1
Close Browser
选择复选框中所有内容
代码语言:javascript复制@{list} Create List 1 2 3
open browser http://127.0.0.1:8080/sec/33/index.html firefox
@{checkboxes} Get Webelements xpath=/html/body/form[2]
FOR ${item} IN @{list}
Click Element id=c${item}
END
FOR ${item} IN @{list}
Checkbox Should Be Selected id=c${item}
END
Close Browser
下拉条
代码语言:javascript复制open browser http://127.0.0.1:8080/sec/32/index.html firefox
sleep 3
Select From List By Value id=ph 华为
Click Button id=button
Alert Should Be Present 我选择的是华为
Select From List By Label id=ph 中兴
Click Button id=button
Alert Should Be Present 我选择的是中兴
Close Browser
关键字
代码语言:javascript复制 open browser https://www.baidu.com firefox
${SearchWords} Set Variable ${words}[${integer}]
Input Text name=wd ${SearchWords}
Click Button id=su
Wait Until Element Is Visible class=n 20
${title} Get Title
Should be Equal ${title} ${SearchWords}_百度搜索
Close Browser
var.py
代码语言:javascript复制import random
__all__ =['scalar','var1','integer','words']
scalar = 'Hello World!'
var1 =['Hello','World','Python']
integer = random.randint(0,8)