WEB端UI自动化测试(七)浏览器Frame切换

在UI自动化测试过程中,新启窗口是经常发生的事,如果要定位元素,就要切换页面。

思路:

1.获取当前所有窗口的句柄,放到list集合中

2.遍历list,按顺序得到页面的句柄

3.switchTo()切换句柄

    Set<String> window_handles ; 
    List<String> list ; //把set集合放入List对象
    public void switchframe() throws InterruptedException{        
        window_handles = driver.getWindowHandles();//获取所有页面的句柄
        list = new ArrayList<String>(window_handles);
        for(String winh:list){
            driver.switchTo().window(winh);
            System.out.println("窗口句柄:"+winh+driver.getTitle());
        }    
        driver.switchTo().window(list.get(list.size()-1)); //切换到弹出的新窗口

    driver.switchTo().window(list.get(0));//返回至原界面
 

 

posted @ 2019-10-17 19:49  归藏  阅读(421)  评论(0)    收藏  举报