zoukankan      html  css  js  c++  java
  • Java+Selenium——window接口相关方法介绍

    windows接口下有几个方法,主要是用来控制浏览器窗口设置,例如窗口大小,最大,最小,全屏,位置。我们先来看看window接口下有什么方法。

    void setSize(Dimension targetSize);
    void setPosition(Point targetPosition);
    Dimension getSize();
    Point getPosition();
    void maximize();
    void fullscreen();

    ============================================================================

    package rjcs;
    
    import java.io.File;
    import java.awt.Rectangle;
    import java.awt.Robot;
    import java.awt.Toolkit;
    import java.awt.image.BufferedImage;
    import org.apache.commons.io.FileUtils;
    import org.openqa.selenium.By;
    import org.openqa.selenium.Point;
    import org.openqa.selenium.TakesScreenshot;
    import org.openqa.selenium.firefox.FirefoxDriver;
    
    import org.openqa.selenium.Dimension;
    import java.text.SimpleDateFormat;
    import org.openqa.selenium.*;
    
    
    public class zmjsj 
    {
        
        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(3000);        
                 
                 driver.manage().window().maximize();         //最大化窗口
                 
                 //driver.manage().window().setSize(new Dimension(400,600));
                 Dimension targetSize = new Dimension(400,600); 
                  driver.manage().window().setSize(targetSize);
                  
                  System.out.println(driver.manage().window().getSize());
    
    
                 
                 Thread.sleep(3000);
                 
                 driver.get("https://www.baidu.com/");  
                 
                 Thread.sleep(3000);
                 
    
                 
    
                 
                  Thread.sleep(10000);
                 
            }catch (Exception e) 
            {
                e.printStackTrace();
            }finally 
            {
                driver.quit();
            
             }
       }
        
    
    }

    ======================================================================================================

    package rjcs;
    
    import java.io.File;
    import java.awt.Rectangle;
    import java.awt.Robot;
    import java.awt.Toolkit;
    import java.awt.image.BufferedImage;
    import org.apache.commons.io.FileUtils;
    import org.openqa.selenium.By;
    import org.openqa.selenium.Point;
    import org.openqa.selenium.TakesScreenshot;
    import org.openqa.selenium.firefox.FirefoxDriver;
    
    import org.openqa.selenium.Dimension;
    import java.text.SimpleDateFormat;
    import org.openqa.selenium.*;
    
    
    public class zmjsj 
    {
        
        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(3000);        
                 
                 driver.manage().window().maximize();         //最大化窗口
                 
                 //driver.manage().window().setSize(new Dimension(400,600));
                 Dimension targetSize = new Dimension(400,600); 
                  driver.manage().window().setSize(targetSize);
                  
                  System.out.println(driver.manage().window().getSize());
    
    
                 
                 Thread.sleep(5000);
                 
                 
                 Point targetPosition = new Point(500, 500);         //设置窗口左上角那个点出现的位置为(300,600)
                 driver.manage().window().setPosition(targetPosition);
                 System.out.println(driver.manage().window().getPosition());
                 
                 Thread.sleep(5000);
                 
                 driver.get("https://www.baidu.com/");  
                 
                 Thread.sleep(3000);
                 
    
                 
    
                 
                  Thread.sleep(10000);
                 
            }catch (Exception e) 
            {
                e.printStackTrace();
            }finally 
            {
                driver.quit();
            
             }
       }
        
    
    }
  • 相关阅读:
    PHP(运算符,语句,函数)
    数据库高级查询
    MySQL数据库常用函数
    mySQL数据库数据查询操作详解
    mySQL数据库设计范式及增删改查操作
    mySQL-创建表
    JavaScript-选项卡
    JavaScript做DIV下拉列表
    JavaScript-事件
    JavaScript函数-递归
  • 原文地址:https://www.cnblogs.com/xiaobaibailongma/p/12219056.html
Copyright © 2011-2022 走看看