使用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");
}
悦分享测试联盟: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");
}
相关文章推荐
- Android 真机,微信打开 H5,切换到 webview,能通过 webdriver 方法操作页面元素,然后链接到新的 H5 页面后,无法操作元素,appium 服务器没有收到 response,
- Web自动化测试(4): Selenium Web Driver 操作控件完成页面自动化测试的例子。
- 使用Selenium-webdriver对页面进行截图操作
- WebDriver拾级而上·之九 等待页面加载元素完成
- Senium 2.0 通过webdriver提供的api完成各种验证操作
- 【WebDriver】selenium使用CSS定位页面元素
- webdrive——frame嵌套页面元素定位,多窗口切换操作,警告弹框处理
- webdriver定位页面元素时使用set_page_load_time()和JavaScript停止页面加载
- selenium webdriver(3)---操作页面对象
- Web自动化测试(3): Selenium Web Driver 如何操作web页面。
- 使用WebElements定位多个相似的元素,比如页面中存在五个单选按钮,他们有相同的class属性,值为:myRadio,我们想对五个按钮循环操作,我们可以把它们全部取出来放到集合中,然后做循环操作
- selenium+python自动化测试(二)--使用webdriver操作浏览器
- webdriver与浏览器_操作页面元素—弹出窗口
- 获取iframe中的内容、查找获取指定元素(关于用c++调用WEBBROWSER控件,使用相关接口操作web页面元素的一些方法)
- selenium webdriver学习(十一)------------如何等待页面元素加载完成
- Selenium_WebDriver登录模拟鼠标移动切换窗体等操作练习(cssSelector初练手)_Java
- 关于Webdriver自动化测试时,页面数据与数据库id不一致的处理方式,需要使用鼠标事件
- Senium 2.0 通过webdriver提供的api完成各种验证操作
- webdriver与浏览器_操作页面元素—单选按钮/多选按钮
- sssp整合&分页之完成添加操作之显示页面&使用JPA二级缓存