자바 작업 복습 - JS 스 크 립 트 실행 - 스크롤 바 02

4345 단어
package jkcs;

import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;

public class jdcs 
{
    
    public static void main(String[] args) throws InterruptedException 
    {
         System.setProperty("webdriver.chrome.bin","‪C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe");    //
        

         
         WebDriver driver = new FirefoxDriver();
         driver.get("http://www.ifeng.com");
         driver.manage().window().maximize();
         
         Thread.sleep(5000);
         
         

         
         
         
         JavascriptExecutor js = ( JavascriptExecutor ) driver;   //    js   
         
         String title = (String) js.executeScript("return document.title"); //      executeScript    js  
         
         System.out.println(title);   //          title 
         
         
         
         
         
         
         Thread.sleep(5000);
         
         
         
         
         JavascriptExecutor jsx = ( JavascriptExecutor ) driver;   //    js   
         
         jsx.executeScript("window.scrollTo(100,1000);"); //      executeScript    js  
         
         
         
         
         
         Thread.sleep(5000);
         
         JavascriptExecutor jsy = ( JavascriptExecutor ) driver;   //    js   
         
         jsy.executeScript("window.scrollTo(100,document.body.scrollHeight);"); //      executeScript    js  ,        
         
         
         
         
         Thread.sleep(5000);
         
         
         WebElement element = driver.findElement(By.linkText("                      "));
         
         JavascriptExecutor jsyx = ( JavascriptExecutor ) driver;   //    js   
         
         jsyx.executeScript("arguments[0].scrollIntoView();",element); //      executeScript    js  ,       
         
         
         
         
         Thread.sleep(5000);
         
         driver.quit();

    }
}

좋은 웹페이지 즐겨찾기