Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

Selenium Learning: mouse event

Shulou Source: shulou.com Published: 2022-06-03 06:36:29 11月23日 Update

The method of mouse operation in WebDriver is encapsulated in the ActionChains class

Common methods provided by the ActionChains class:

Perform (): performs storage behavior in all ActionChains

Contextclick () right-click

Double_click () double click

Drag_and_drop () drag

Move_to_element () Mouse hover

Right mouse click event

In the following code: from selenium.driver import ActionChains imports the ActionChains class that provides mouse operation

ActionChains (driver) calls the ActionChains class, passing in the browser-driven driver as an argument

The context_click (right_click) method is used to simulate the right mouse button operation, and the element location needs to be specified when called.

Perform () performs all the storage behaviors in ActionChains, committing actions for the entire operation.

two。 The mouse hover move_to_element () method can simulate the action of mouse hover 3. Double click the mouse using the double_click function 4. Mouse drag and drop operation drag_and_drop (source,target) hold down the left mouse button on the source element Then move to the target machine to release source: mouse dragged source element target mouse released target element 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) # positioning element right_click= driver.find_element_by_xpath ('/ * [@ id=" U1 "] / A [8]') # right-click ActionChains (driver). Context_click (right_click). Perform () # Mouse hover # ActionChains (driver). Move_to_element (right_click). Perform () # double-click ActionChains (driver). Double_click (right_click). Perform () sleep (3) driver.quit ()

Tags: Mouse element method action goal behavior storage location event code function parameter commonly used browser encapsulation browsing moving driving learning Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Xiaomi Shulou Tech Info MySQL MariaDB OPPO Reno