zoukankan      html  css  js  c++  java
  • Selenium 新窗口处理方法

    有时点击一个链接,跳到一个新的窗口,这时WebDriver需切换到新窗口,才能对新窗口的元素进行操作

    这里封装一个switchToWindow方法:

        public boolean switchToWindow(WebDriver driver,String windowTitle){  
            boolean flag = false;  
            try {  
                String currentHandle = driver.getWindowHandle();  
                Set<String> handles = driver.getWindowHandles();  
                for (String s : handles) {  
                    if (s.equals(currentHandle))  
                        continue;  
                    else {  
                        driver.switchTo().window(s);  
                        if (driver.getTitle().contains(windowTitle)) {  
                            flag = true;  
                            System.out.println("Switch to window: "  
                                    + windowTitle + " successfully!");  
                            break;  
                        } else  
                            continue;  
                    }  
                }  
            } catch (NoSuchWindowException e) {  
                System.out.println("Window: " + windowTitle  
                        + " cound not found!");  
                flag = false;  
            }  
            return flag;  
        }  

    }



  • 相关阅读:
    vim配置文件解析
    VIM使用技巧5
    补不manjaro系统
    linux下终端录制
    VIM的修炼等级
    VIM使用技巧4
    64位linux 汇编
    linux下编译安装gcc5.1
    Git学习笔记
    HTML实体符号代码速查表
  • 原文地址:https://www.cnblogs.com/wuyepiaoxue/p/5661176.html
Copyright © 2011-2022 走看看