Selenium2.0功能测试之如何使用Action类来模拟交互(Java版)
Selenium提供了一个强大的用于真实的模拟用户交互的一个类----Actions,这个类提共了一系列的API供模拟交互:
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();}}