Selenium mouse event operation

1. Class for operating mouse events: ActionChains 

  perform () executes all actions stored in ActionChains

  context_click () right click

  double_click () double-click

  drag_and_drop () drag

   move_to_element () mouseover

2. Right mouse click example

from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
import time

driver = webdriver.Firefox()
driver.get("http://passport.kuaibo.com/login/?referrer=http%3A%2F%2Fwebcloud.kuaibo.com%2F")

#登陆快播私有云
driver.find_element_by_id("user_name").send_keys("username")
driver.find_element_by_id("user_pwd").send_keys("123456")
driver.find_element_by_id ( " dl_an_submit " ) .click () 
the time.sleep ( . 3 ) 

# targeting element to right click 
QQQ driver.find_element_by_xpath = ( " / HTML / body / div / div [2] / div [2] / div / div [3] / table / tbody / tr / td [2] " )
 # Right-click on the positioned element 
ActionChains (driver) .context_click (qqq) .perform ()

3. The operation of dragging the mouse 

# Positioning the home position of the element 
Element driver.find_element_by_name = ( " Source " )
 # positioning element to move to the target position of the 
target driver.find_element_by_name = ( " target " ) 

# execute moving operation element 
ActionChains (driver) .drag_and_drop (element, target) .perform ()

 

Guess you like

Origin www.cnblogs.com/pipile/p/12711171.html