zoukankan      html  css  js  c++  java
  • java+selenium+new——使用title属性识别和操作新弹出的浏览器窗口

    package rjcs;
    
    
    
    import java.util.*;
    
    import org.openqa.selenium.WebElement;
    import org.openqa.selenium.firefox.FirefoxDriver;
    import org.openqa.selenium.interactions.Actions;
    import org.openqa.selenium.support.ui.Select;
    
    public class xinkaishi 
    {
    
        
        public static void main(String[] args)
        
        {
             System.setProperty("webdriver.firefox.bin","C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe");    //设置火狐的安装路径,防止系统找不到
                
             FirefoxDriver driver = new FirefoxDriver();        //初始化FireFox浏览器实例,并打开浏览器
             
            try
            {
                 driver.manage().window().maximize();         //最大化窗口
                 
                 Thread.sleep(5000);    
                 
                 driver.navigate().to("http://yancheng.ganji.com/"); 
                 
                 Thread.sleep(5000);
                 
                 
                 String parentWindowHandle = driver.getWindowHandle();  //先将当前浏览器窗口句柄存储到变量中。
                 
                 driver.findElementByLinkText("包吃包住").click();
                 
                 
                 Set<String> allWindowsHandles = driver.getWindowHandles();  //把打开的所有浏览器句柄,存放到一个set容器中
                 
                 
                 if ( !allWindowsHandles.isEmpty() )
                 {
                     for (  String windowHandle : allWindowsHandles )
                     {
                         System.out.println(driver.switchTo().window(windowHandle).getTitle());
                         
                         Thread.sleep(10000);
                     }
                 }
                            
                 
                 Thread.sleep(10000);
                 
                 
            }catch (Exception e) 
            {
                e.printStackTrace();
            }finally 
            {
                driver.quit();
            
             }
        }
        
        
        
    }

    执行结果:

    【盐城赶集网】-免费发布信息-盐城分类信息门户
    【盐城找工作|找工作信息|盐城找工作网站】 - 盐城赶集网

  • 相关阅读:
    编程技术网站汇总
    SQL中select与set的区别-转载
    JQuery 了解
    Html--表单练习
    SqlServer--聚合函数
    SqlServer--模糊查询-通配符
    SqlServer-- NULL空值处理
    Sql--order by、desc降序、top
    Nginx+Tomcat+Memcached集群
    配置Nginx服务
  • 原文地址:https://www.cnblogs.com/xiaobaibailongma/p/12289536.html
Copyright © 2011-2022 走看看