码迷,mamicode.com
首页 > 编程语言 > 详细

java selenium webdriver处理JS操作窗口滚动条

时间:2016-12-12 23:39:09      阅读:329      评论:0      收藏:0      [点我收藏+]

标签:height   software   sof   style   class   win   max   drivers   throw   

未经作者允许,禁止转载!!!

java selenium webdriver处理JS操作窗口滚动条

java selenium webdriver处理JS操作窗口滚动条

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

public class JS20161212 {

    public static void main(String[] args) throws InterruptedException {
        // TODO Auto-generated method stub
        System.setProperty("webdriver.chrome.driver","C:\\Training\\Automation\\Software\\drivers\\chromedriver_win32\\chromedriver.exe");
        WebDriver driver=new ChromeDriver();
        driver.get("https://www.hao123.com/");
        driver.manage().window().maximize();
        Thread.sleep(2000);
        
        JavascriptExecutor js = (JavascriptExecutor)driver;
        js.executeScript("scrollTo(0,10000)");----------------------------------------------向下拉到底
        Thread.sleep(2000);
        js.executeScript("scrollBy(0, 0-document.body.scrollHeight *99/100)");--------------向上拉到顶
        Thread.sleep(2000);
        js.executeScript("scrollTo(0,100000)");---------------------------------------------向下拉到底
        Thread.sleep(2000);
        js.executeScript("scrollTo(0,1)");--------------------------------------------------向上拉到顶
        Thread.sleep(2000);
        js.executeScript("scrollTo(0,1000)");
        Thread.sleep(2000);
        js.executeScript("scrollBy(0, 0-document.body.scrollHeight *1/2)");-----------------拉到中间
        Thread.sleep(2000);
        js.executeScript("scrollBy(0, 0-document.body.scrollWidht *1/2)");------------------左右拉到中间
        
    
//      ((JavascriptExecutor)driver).executeScript("scrollTo(0,10000)");----------------精简后的代码
//      Thread.sleep(2000);
//      ((JavascriptExecutor)driver).executeScript("scrollTo(0,1)");

    }

}

 

java selenium webdriver处理JS操作窗口滚动条

 

java selenium webdriver处理JS操作窗口滚动条

标签:height   software   sof   style   class   win   max   drivers   throw   

原文地址:http://www.cnblogs.com/111testing/p/6166060.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!