package org.coderinfo.demo; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.interactions.Actions; public class ActionDemo { private static final String URL = "http://www.baidu.com"; /** * @author Coderinfo * @E-mail coderinfo@163.com */ public static void main(String[] args) throws InterruptedException { WebDriver driver = new ChromeDriver(); driver.manage().window().maximize(); //最大化浏览器界面 driver.get(URL); //访问度娘首页。 Thread.sleep(2000); //等待页面加载 WebElement input = driver.findElement(By.id("kw")); //获取 百度搜索框 Actions ac = new Actions(driver); // 为driver 加载 actions ac.contextClick(input).perform(); // 在百度搜索框上点击右键 Thread.sleep(10000); driver.quit(); } } |