通过pip安装扩展库:
pip install robotframework-seleniumlibrary==3.0.0
下载谷歌游览器和对应驱动
selenium之使用chrome浏览器测试(附chromedriver与chrome的对应关系表) - W- - 博客园
找到对应的版本进行下载
将游览器驱动放在python的目录下
导入SeleniumLibrary扩展库
Maximize Browser Window
打开游览器(访问网站)
Open Browser 关键字 http://www.baidu.com 网址 chrome浏览器
设置睡眠时间
leep 时间(秒)
Set Browser Implicit Wait 时间(秒)
3:窗口最大化
Maximize Browser Window
设置窗口位置
Set Window Position 20 40
返回上一步
Go Back
跳转
Go To关键字 http://www.baidu.com网址
刷新
Reload Page
关闭浏览器
Close Browser
selenium中八大定位方式:
id,name,xpath,css,link_text,partial_link_text,class_name,tag_name
xpath
1:通过绝对路径定位元素:
2:通过相对路径定位元素:xpath=//form/span/input
3:通过元素属性定位元素:xpath=//input[@autocomplete="off" and @class="s_ipt"]
4:通过部分元素属性定位:xpath=//input[contains(@autocomplete="of")]
5:通过元素文本定位元素:xpath=//a[text()="新闻"]
css
1:通过id进行定位:#ID
2:通过class定位:.class
3:通过元素属性定位:css=input[autocomplete="off"]
4:通过部分属性定位:css=input[autocomplete*="of"]
5:通过子元素定位:css=div#s-top-left a:nth-child(3)
id定位:
Comment id定位
Input Text id=kw 12306
name定位:
Comment name定位
Input Text name=wd 12306
link点击
Comment link定位
Click Element link=直播
partial_link定位
Comment partial link
Click Element partial link=直播
xpath定位
css定位