上一篇文章中,简单模拟了一个baidu搜索并截图的过程,在搜索过程中,我们需要对搜索框、搜索按钮进行定位。本篇文章主要介绍一下具体的定位方法。
我们的脚本如下:
*** Settings ***
Library Selenium2Library
*** Test Cases ***
firefox兼容性
Open Browser https://www.baidu.com/ ff
Input Text id=kw LeetTest
Click button id=su
Sleep 2 Capture Page Screenshot ff.png Close Browser
这里我们用到了Selenium2Library进行浏览器控制。接下来查找Selenium2Library的官方文档,来查看如何进行页面元素定位。
在Github上搜索Selenium2Library,项目地址为
https://github.com/rtomac/robotframework-selenium2library
查看其wiki,可以找到它的官方文档
http://rtomac.github.io/robotframework-selenium2library/doc/Selenium2Library.html
其中的Locating or specifying elements 章节,介绍了进行元素定位的几种方法:
以脚本
Click Element my_element
为例,定位方法可采用以下方法:
Strategy |
Example |