Selenium + Java (nine) Selenium keyboard and mouse events

First, the keyboard events

ctrl+a

driver.findElement(By.id("kw")).sendKeys(Keys.CONTROL, "a");

ctrl+x

driver.findElement(By.id("kw")).sendKeys(Keys.CONTROL, "x");

ctrl+c

driver.findElement(By.id("kw")).sendKeys(Keys.CONTROL, "c");

ctrl+v

driver.findElement(By.id("kw")).sendKeys(Keys.CONTROL, "v");

F key operation

// F.-F12 keys need Fl 
driver.findElement (By.id ( "kW")) sendKeys (Keys.F5).;

TAB key

driver.findElement(By.id("kw")).sendKeys(Keys.TAB);

enter

driver.findElement(By.id("kw")).sendKeys(Keys.ENTER);

space bar

driver.findElement(By.id("kw")).sendKeys(Keys.SPACE);

There are other keyboard operation, just to name a common keys.

Second, mouse events

right click

Actions = Actions new new Actions (Driver);
 // Right-click-click enement to target elements 
actions.contextClick (element) .perform ();

Left-click

Actions = Actions new new Actions (Driver);
 // left mouse button click enement to define the elements 
actions.clickAndHold (element) .perform ();

Double-click the Mouse

Actions = the Actions new new the Actions (Driver);
 // double click enement element to define 
actions.doubleClick (element) .perform ();

Hover

Actions actions = new Actions(driver);
//鼠标悬停
actions.moveToElement(element).perform();

Guess you like

Origin www.cnblogs.com/yogouo/p/11949158.html