zoukankan      html  css  js  c++  java
  • selenium 切换窗口 每次成功code

    最近用了网络上别人的一段切换窗口的code每次成功了,不错,学习

    // 根据Title切换新窗口
    	public boolean switchToWindow_Title(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 find!!!"
    					+ e.fillInStackTrace());
    			flag = false;
    		}
    		return flag;
    	}
    
    // 根据URL切换新窗口
    	public boolean switchToWindow_Url(WebDriver driver, String windowUrl) {
    		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.getCurrentUrl().contains(windowUrl)) {
    						flag = true;
    						System.out.println("Switch to Window: " + windowUrl
    								+ "  successfully~~~!");
    						break;
    					} else
    						continue;
    				}
    			}
    		} catch (NoSuchWindowException e) {
    			System.out.println("Window: " + windowUrl + " cound not find!!!"
    					+ e.fillInStackTrace());
    			flag = false;
    		}
    		return flag;
    	}
    
  • 相关阅读:
    Mysql常用命令
    Centos7初始配置
    centos7配置mysql
    CentOS7 配置阿里云yum源
    Dockerfile
    Centos7部署hadoop 3
    Windows10安装docker
    centos7安装docker
    大数据与分布式架构
    Centos7单主机部署 LAMP + phpmyadmin 服务
  • 原文地址:https://www.cnblogs.com/sschen/p/3614117.html
Copyright © 2011-2022 走看看