zoukankan      html  css  js  c++  java
  • Java+Selenium——利用Javascript处理滚动条——利用webdriver执行脚本直接滚动到指定坐标位置

    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);
    
                 driver.get("https://www.baidu.com/");  
                 
                 
                 
                 Thread.sleep(5000);
                 
                 ((JavascriptExecutor)driver).executeScript("scrollTo(0,300)");
                 
                 
                 Thread.sleep(5000);
                 
                 ((JavascriptExecutor)driver).executeScript("scrollTo(600,600)");
                 
                 
                  Thread.sleep(10000);
                 
            }catch (Exception e) 
            {
                e.printStackTrace();
            }finally 
            {
                driver.quit();
            
             }
       }
        
    
    }
  • 相关阅读:
    GAMBIT、ICEM、HYPERMESH耦合面的处理方法
    如何用hypermesh生成包含interface的流体网格
    python求数字位数的方法
    drawPython
    Python入门计划
    书法与篆刻创作结课
    易忽视的Python知识点
    Ubuntu中,wxpython的TextCtrl引发的error:_pixman_log_error
    在Ubuntu15.10中,使用wxPython的webview和JS进行交互
    PyCharm导入tensorflow包
  • 原文地址:https://www.cnblogs.com/xiaobaibailongma/p/12219082.html
Copyright © 2011-2022 走看看