
1package rjcs; 2 3import org.openqa.selenium.By; 4import org.openqa.selenium.Keys; 5import org.openqa.selenium.WebElement; 6import org.openqa.selenium.firefox.FirefoxDriver; 7import org.openqa.selenium.interactions.Actions; 8 9public class a 10{ 11 public static void main(String[] args) 12 13 { 14 System.setProperty("webdriver.firefox.bin","C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe"); //设置火狐的安装路径,防止系统找不到 15 16 FirefoxDriver driver = new FirefoxDriver(); //初始化FireFox浏览器实例,并打开浏览器 17 18 try 19 { 20 driver.manage().window().maximize(); //最大化窗口 21 22 Thread.sleep(5000); 23 24 25 driver.get("https://www.baidu.com"); 26 27 Thread.sleep(5000); 28 29 30 31 Actions action = new Actions(driver); 32 33 34 Thread.sleep(5000); 35 36 37 action.contextClick(driver.findElementByLinkText("地图")).perform(); //鼠标在某个元素上右击 38 39 40 41 Thread.sleep(5000); 42 43 44 action.contextClick(driver.findElementById("kw")).perform(); 45 46 47 Thread.sleep(10000); 48 49 50 }catch (Exception e) 51 { 52 e.printStackTrace(); 53 }finally 54 { 55 driver.quit(); 56 57 } 58 } 59}