Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Selenium Learning: mouse event

2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/03 Report--

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 ()

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report