Selenium Test (Java)--keyboard events

Source: Internet
Author: User
Tags xpath

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.