selenium 学习5 -- 基本操作

来源:互联网 发布:券商 风控 知乎 编辑:程序博客网 时间:2024/05/16 01:05

在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");

从而避免 等待时长不确定问题


原创粉丝点击