selenium实际应用中的基本方法

2012-05-24  付民 

在java类中使用selenium进行web测试的一些基本操作如下所示:
1、打开网页: selenium.open("http://www.xxx.com/");// 使用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");
562°/5628 人阅读/0 条评论 发表评论

登录 后发表评论