자바 작업 복습 - JS 스 크 립 트 실행 - 버튼 클릭

2670 단어
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.baidu.com");
         driver.manage().window().maximize();
         
         Thread.sleep(5000);
         
         

         driver.findElement(By.id("kw")).sendKeys("  ");
         
         
         Thread.sleep(5000);
         
         
         
         WebElement element = driver.findElement(By.id("su"));
         
         JavascriptExecutor js = ( JavascriptExecutor ) driver;   //    js   
         
         js.executeScript("arguments[0].click();",element); //      executeScript    js  
         
         
         
         
         
         

         
         
         Thread.sleep(5000);
         
         driver.quit();

    }
}

좋은 웹페이지 즐겨찾기