Selenium Test (Java)-Mouse events

Source: Internet
Author: User
Tags xpath

Mouse Operation:

1. Right-click

2. Double-click

3. Drag to

4. Hover

1  PackageCom.test.mouse;2 3 ImportJava.io.File;4 5 Importorg.openqa.selenium.By;6 ImportOrg.openqa.selenium.WebDriver;7 Importorg.openqa.selenium.WebElement;8 ImportOrg.openqa.selenium.firefox.FirefoxDriver;9 ImportOrg.openqa.selenium.firefox.FirefoxProfile;Ten Importorg.openqa.selenium.interactions.Actions; One  A  Public classmouseoperation { -  -      Public Static voidMain (string[] args) { theFirefoxprofile profile =NewFirefoxprofile ( -                 NewFile ("C:\\users\\xxxx\\appdata\\roaming\\mozilla\\firefox\\profiles\\a6xwo0b1.default")); -Webdriver Driver =Newfirefoxdriver (profile); -  +Driver.get ("http://c37.yunpan.360.cn"); - driver.manage (). window (). Maximize (); +WaitTime (5000); A  atDriver.findelement (By.xpath ("//*[@id = ' Infopanel ']/a[2]") . Click (); -WaitTime (3000); -  -Driver.findelement (By.xpath ("//*[@id = ' Tbtext ']") . Click (); -Webelement TestItem = driver.findelement (By.xpath ("//*[@id = ' list ']/li[1]/div[2]/span[2]")); - Testitem.click (); inWaitTime (3000); -  to         //left-click implementation (similar to element's click) +        Actions action = new actions (driver); -Webelement Test1item = driver.findelement (By.xpath ("//*[@id = ' list ']/li[1]/div[2]/span[2]")); the action. Click (Test1item) . Perform (); *WaitTime (5000); $ Panax Notoginseng         //back to previous level -Driver.findelement (By.xpath ("//*[@id = ' crumb ']/div/span[1]") . Click (); theWaitTime (5000); +  A         //Double-click Implementation the         NewActions (Driver). DoubleClick(Driver.findelement (By.xpath ("//*[@id = ' list ']/li[1]/div[2]/span[2]")) . Perform (); +WaitTime (5000); -  $         //back to previous level $Driver.findelement (By.xpath ("//*[@id = ' crumb ']/div/span[1]") . Click (); -WaitTime (5000); -  the         //Hover over More button implementations -         NewActions (Driver). Movetoelement(Driver.findelement (By.xpath ("//*[@id = ' Toppanel ']/ul/li[3]/a")) . Perform ();Wuyi  the         //Drag implementation -Driver.findelement (By.xpath ("//*[@id = ' tbpic ']") . Click (); WuWebelement begin = Driver.findelement (By.xpath ("//*[@id = ' list ']/li[1]/div[2]/span[1]")); -Webelement end = Driver.findelement (By.xpath ("//*[@id = ' list ']/li[2]/div[2]/span[1]")); About         NewActions (Driver). Draganddrop(begin, end). Perform (); $  -         //Right-click to implement -         //Although the use of the element is still test1item, but the page after the refresh needs to reposition -         //refer to http://docs.seleniumhq.org/exceptions/stale_element_reference.jsp ADriver.findelement (By.xpath ("//*[@id = ' Tbtext ']") . Click (); +         NewActions (Driver). Contextclick(Driver.findelement (By.xpath ("//*[@id = ' list ']/li[1]/div[2]/span[2]"))) the  . Perform (); -WaitTime (5000); $  theDriver.findelement (By.xpath ("//*[@id = ' x-yp-3 ']/ul/li[4]/a/span") . Click (); theWaitTime (5000); the  the driver.quit (); -  in     } the  the     Static  Public voidWaitTime (intTime ) { About  the         Try { the Thread.Sleep (time); the}Catch(interruptedexception e) { +             //TODO auto-generated Catch block - e.printstacktrace (); the         }Bayi     } the  the}

Note: The role of Perform () is to perform the behavior stored in all actions.

Selenium Test (Java)-Mouse events

Related Article

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.