1 PackageCom.test.key;2 3 Importorg.openqa.selenium.By;4 ImportOrg.openqa.selenium.Keys;5 ImportOrg.openqa.selenium.WebDriver;6 ImportOrg.openqa.selenium.firefox.FirefoxDriver;7 8 Public classKeyB {9 Ten Public Static voidMain (string[] args) { OneWebdriver Driver =Newfirefoxdriver (); ADriver.get ("http://www.baidu.com"); - driver.manage (). window (). Maximize (); - the //Input Box input content -Driver.findelement (By.xpath ("//*[@id = ' kw ')"). SendKeys ("Selenium"); - - //Delete a M +Driver.findelement (By.xpath ("//*[@id = ' kw ']") . SendKeys (keys.back_space); - + //Enter m space tutorial ADriver.findelement (By.xpath ("//*[@id = ' kw ')"). SendKeys ("M"); atDriver.findelement (By.xpath ("//*[@id = ' kw ']") . SendKeys (keys.space); -Driver.findelement (By.xpath ("//*[@id = ' kw ')"). SendKeys ("tutorial"); - - //Select all input box contents -Driver.findelement (By.xpath ("//*[@id = ' kw ')"). SendKeys (Keys.control, "a"); - in //Cut input Box contents -Driver.findelement (By.xpath ("//*[@id = ' kw ')"). SendKeys (Keys.control, "X"); to + //Paste Input Box Contents -Driver.findelement (By.xpath ("//*[@id = ' kw ')"). SendKeys (Keys.control, "V"); the * //Replace the commit action with a carriage return $Driver.findelement (By.xpath ("//*[@id = ' kw ']") . SendKeys (keys.enter);Panax Notoginseng -WaitTime (5000); the driver.quit (); + } A the Static Public voidWaitTime (intTime ) { + - Try { $ Thread.Sleep (time); $}Catch(interruptedexception e) { - //TODO auto-generated Catch block - e.printstacktrace (); the } - }Wuyi the}
Selenium Test (Java)--keyboard events