您的位置:首页 > 其它

使用WebDriver完成web页面切换操作(附源码)

2013-07-31 21:49 375 查看
测试技术交流群:161204772

悦分享测试联盟:136924235

悦分享主页:http://www.bjhxcc.com/special/2013/0822/yfx.htm
public void testBaidu() throws Exception {

driver.get("http://www.baidu.com");

String parentID = driver.getWindowHandle();
//save current windowHandle

driver.findElement(By.linkText("新 闻")).click();

Set<String> allID = driver.getWindowHandles();
//save all opened windowHandle

if(allID.remove(parentID)){ //remove the first windowhandle

System.out.println("remove the first windowHandle success");

}

Iterator<String> iter = allID.iterator();

while(iter.hasNext()){

driver.switchTo().window(iter.next());//swith to the second handle

driver.getCurrentUrl();

}

driver.findElement(By.linkText("总政治部副主任吴昌德等6人晋升上将")).click();

Thread.sleep(5000);

System.out.println("it's over");

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐