package jkcs; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.interactions.Actions; 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(); //初始化FireFox浏览器实例,并打开浏览器 driver.manage().window().maximize(); //最大化窗口 driver.navigate().to("http://www.baidu.com"); Thread.sleep(5000); driver.findElement(By.id("kw")).sendKeys("china"); //文本框里输入 Thread.sleep(5000); Actions sj = new Actions(driver); sj.click(driver.findElement(By.id("su"))).perform(); //模拟鼠标左击 Thread.sleep(8000); driver.quit(); } }