import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;
public class selenium_mouse_action {
/*webdriver中的鼠标操作方法由ActionChains类提供
ActionChains 类提供的鼠标操作的常用方法:
perform() 执行所有ActionChains 中存储的行为
contextClick() 右击
doubleClick() 双击
dragAndDrop() 鼠标拖拽
clickAndHold() 鼠标悬停
click() 单击*/
public static void main(String[] args) {
WebDriver driver=new FirefoxDriver();
driver.get("http://www.baidu.com/");
Actions action=new Actions(driver);
//action.contextClick(driver.findElement(By.id("su"))).perform();//鼠标右击
action.clickAndHold(driver.findElement(By.linkText("设置"))).perform();//鼠标悬停
//action.moveToElement(driver.findElement(By.linkText("设置"))).perform();//鼠标单击
//action.duobleClick("定位到的元素").perform();//鼠标双击
//鼠标拖拽操作
//WebElement source=driver.findElement("");
//WebElement target=driver.findElement("");
//action.dragAndDrop(source,target).perform();
}
}