• 如何得到新打开的窗口


    import java.io.File;
    import java.util.Iterator;
    import java.util.Set;

    import org.openqa.selenium.By;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.chrome.ChromeDriver;

    /*
     * 如何得到新打开的窗口
     */
    public class PopupWindowTest {

        public static void main(String[] args) {
            WebDriver dr = new ChromeDriver();
            File file = new File("learning/test.html");
            String filePath = "file:///" + file.getAbsolutePath();
            System.out.println(filePath);

            dr.get(filePath);
            dr.findElement(By.id("51")).click();

            // 得到当前窗口句柄
            String currentWindow = dr.getWindowHandle();

            Set<String> handles = dr.getWindowHandles();
            Iterator<String> it = handles.iterator();

            while (it.hasNext()) {
                String tmp = it.next();
                if (currentWindow.equals(tmp))            // currentWindow == tmp  返回 false  字符串值比较用 equals, 字符串 == 比较的是地址
                    continue;

                WebDriver window = dr.switchTo().window(tmp);
                System.out.println("title = " + window.getTitle() + " , url = "
                        + window.getCurrentUrl());
            }

            /*
             * while (it.hasNext()) { if (currentWindow == it.next()) continue;
             *
             * WebDriver window = dr.switchTo().window(it.next());
             * System.out.println("title = " + window.getTitle() + " , url = " +
             * window.getCurrentUrl()); }
             */

            dr.quit();
        }

    }

  • 相关阅读:
    求100-999之间所有的水仙花数
    验证用户密码程序
    【bzoj2002】[Hnoi2010]Bounce 弹飞绵羊 分块/LCT
    【bzoj1070】[SCOI2007]修车 最小费用流
    【bzoj3669】[Noi2014]魔法森林 Kruskal+LCT
    【bzoj3668】[Noi2014]起床困难综合症 贪心
    【bzoj1391】[Ceoi2008]order 网络流最小割
    【bzoj4873】[Shoi2017]寿司餐厅 最大权闭合图
    【bzoj1180】[CROATIAN2009]OTOCI LCT
    【bzoj3282】Tree LCT
  • 原文地址:https://www.cnblogs.com/Roger1227/p/3833688.html
Copyright © 2020-2023  润新知