六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 448|回复: 0

selenium 学习笔记5---基本操作

[复制链接]

升级  64%

8

主题

8

主题

8

主题

童生

Rank: 1

积分
32
 楼主| 发表于 2013-2-8 01:02:47 | 显示全部楼层 |阅读模式
在java类中使用selenium进行web测试的一些基本操作如下所示:
1、打开网页: selenium.open("http://www.xxx.com.cn/");// 使用open时候,不需进行 waitForPageToLoad 调用
2、等待页面: selenium.waitForPageToLoad("20000"); 使用场景如:selenium.click("buttonorlink"); 当点击了按钮后调用该方法,等待页面的打开
3、点击按钮: selenium.click("css=input[type=button]");
4、文 本 框: selenium.type("name", "cxr1217"); 输入
                  selenium.getValue("name"); 得到
5、下拉列表: selenium.select("cities", "label=hebei"); 选中选项
                 
selenium.getSelectOptions("cities"); 得到所有选项
6、复选单选: selenium.check("radioname"); 选中
                  selenium.isChecked("radioname");是否选中
7、关闭alert对话框: if(selenium.isAlertPresent()) {
                                 selenium.getAlert(); //获得当前的alert窗口的值,获得后该窗口即被关闭 
                           }
8、选中子窗口: selenium .waitForPopUp("myPopupWindow", "30000");等待出现
                    
selenium .selectWindow("name=myPopupWindow"); 选中子窗口
                     selenium .close();
关闭子窗口.                 
                     selenium .selectWindow(null); 退回主窗口.
9、selenium.waitForCondition("var msg = selenium.getAlert();msg.match(\""+msg+"\")","10000");
这个waitForCondition("javascript","timeout")方法是目前为止我最喜欢的,可以使用js语法运行,在规定时间内 “timeout”,直到获取该js的值,返回。使用该方法在大部分场景上可以代替 waitForPageToLoad("20000");
从而避免 等待时长不确定问题
 
 
随着selenium的使用深入,会不断添加……
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表