1 package Com.test.key; 2 3 Import Org.openqa.selenium.By; 4 Import Org.openqa.selenium.Keys; 5 Import Org.openqa.selenium.WebDriver; 6 Import Org.openqa.selenium.firefox.FirefoxDriver; 7 8 public class KeyB {9, public static void main (string[] args) {One webdriver driver = new Firefoxdriver ( ); Driver.get ("http://www.baidu.com"); Driver.manage (). window (). Maximize (); 14 15//Input Box Input content: Driver.findelement (By.xpath ("//*[@id = ' kw ')"). SendKeys ("Selenium"); 17 18//Delete a M19 Driver.findelement (By.xpath ("//*[@id = ' kw ')"). SendKeys (Keys.back_space); 20 21//Enter M space tutorial in driver . Findelement (By.xpath ("//*[@id = ' kw ')"). SendKeys ("M"); Driver.findelement (By.xpath ("//*[@id = ' kw ')"). SendKeys (Keys.space), Driver.findelement (By.xpath ("//*[@id = ' kw ')"). SendKeys ("tutorial"); 25 26//Select all input Box Contents 27 Driver.findelement (By.xpath ("//*[@id = ' kw ')"). SendKeys (Keys.control, "a"); 28 29//Cut input Box Contents driver.findelement (By.xpath ("//*[@id = ' kw ')"). SendKeys (Keys.control, "X"); 31 3 2//Paste input box content driver.findelement (By.xpath ("//*[@id = ' kw ')"). SendKeys (Keys.control, "V"); 34 35 Replace the commit action by a carriage return of driver.findelement (By.xpath ("//*[@id = ' kw ')"). SendKeys (Keys.enter); PNs Waitti Me (driver.quit);}41-static public void waitTime (int time) {45 Thread.Sleep (time); Interruptedexception} catch (e) {//TODO auto-generated catch block48 E.printstacktrace (); 49}50}51 52}
Selenium Test (Java)--keyboard events (vii)