Selenium Learning: Mouse events

Source: Internet
Author: User

The method of mouse operation in Webdriver encapsulated in the Actionchains class

Common methods provided by the Actionchains class:

Perform (): Performs the storage behavior in all Actionchains

Contextclick () Right-click

Double_click () Double-click

Drag_and_drop () drag

Move_to_element () mouse hover

    1. Mouse Right-click event

in the following code: from selenium.driver import actionchains Import Actionchains class that provides mouse action

Actionchains (driver) calls the Actionchains class, passing the browser driver driver as a parameter

The Context_click (Right_click) method is used to simulate the right mouse button operation, which requires the specified element to be positioned when called

Perform () performs all the storage behavior in the Actionchains, committing to the entire operation.

2. Mouse hover Move_to_element () method can simulate mouse hover action 3. Mouse double-click operation using Double_click function 4. Mouse drag-and-drop Operation Drag_and_drop (Source,target) hold down the left mouse button on the source element, And then move to the target to release the source: mouse Drag the target element of the mouse to release from selenium import webdriverfrom time import *from Selenium.webdriver.common.action_chains Import actionchainsdriver = Webdriver. Chrome () url = "https://www.baidu.com" Print (' new access%s '% (URL)) driver.get (URL) #定位元素right_click = Driver.find_ Element_by_xpath ('//*[@id = "U1"]/a[8] ') #鼠标右击ActionChains (driver). Context_click (Right_click). Perform () #鼠标悬停 # Actionchains (Driver). Move_to_element (Right_click). Perform () #鼠标双击ActionChains (driver). Double_click (Right_click) . Perform () sleep (3) driver.quit ()

Selenium Learning: Mouse 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.