Selenium之常用的方法的封装

发表于:2016-1-12 11:25

字体: | 上一篇 | 下一篇 | 我要投稿

 作者:li_wu    来源:51Testing软件测试网采编

1 /**
2      * 判断对象是否存在
3      * @param key
4      * @param replace
5      * @return
6      */
7     public boolean isExist(String key,String[] replace){
8         By by=this.getBy(key, replace);
9         return driver.findElements(by).size()>0?true:false;
10     }
1 public void sleep(int sec){
2         try {
3             Thread.sleep(sec*1000);
4         } catch (InterruptedException e) {
5             e.printStackTrace();
6         }
7     }
1 public void click(){
2         log.info("click the element:"+key);
3         element.click();
4     }
5
6     public void sendKeys(String value){
7         log.info("type the value:"+value+" to element:"+key);
8         element.sendKeys(value);
9     }
10
11     public void selectKeys(String text){
12         log.info("select the text:"+text+" to element:"+key);
13         Select select=new Select(element);
14         select.selectByVisibleText(text);
15     }
1 public void moveToElement(){
2         log.info("move to element: "+key);
3         Actions action = new Actions(driver);
4         action.moveToElement(element).perform();
5     }
6
7     public void executeJS(String js){
8         log.info("execute the js: "+js+" at element: "+key);
9         ((JavascriptExecutor)driver).executeScript(js, element);
10     }
11
12     public void waitClickToLoad(){
13         log.info("click the element:"+key);
14         WebDriverWait waitLoad = new WebDriverWait(driver,Config.waitTime);
15         waitLoad.until(new ExpectedCondition<WebElement>(){
16             @Override
17             public WebElement apply(WebDriver d) {
18                 return element;
19             }}).click();
20     }
21
22     public void switchToFrame(int index){
23         if(index==-1){
24             log.info("返回默认窗口");
25             driver.switchTo().defaultContent();
26             log.info("返回默认窗口成功");
27         }else{
28             log.info("切换到第一个frame");
29             driver.switchTo().frame(index);
30         }
31     }
22/2<12
《2023软件测试行业现状调查报告》独家发布~

关注51Testing

联系我们

快捷面板 站点地图 联系我们 广告服务 关于我们 站长统计 发展历程

法律顾问:上海兰迪律师事务所 项棋律师
版权所有 上海博为峰软件技术股份有限公司 Copyright©51testing.com 2003-2024
投诉及意见反馈:webmaster@51testing.com; 业务联系:service@51testing.com 021-64471599-8017

沪ICP备05003035号

沪公网安备 31010102002173号