webdriervAPI (mouse events)

from  selenium  import  webdriver

from selenium.webdriver.common.action_chains import ActionChains introduction of mouse class ActionChains

driver  =  webdriver.Chorme()

driver.get("http://www.baidu.com")

 

ActionChains class provides a common method of operation of the mouse:

  perform () to perform all acts ActionChains stored

  Right-click context_click

  Double-click double_click

  drag_and_drop drag

  move_to_element Hover

 

Right-click mouse operation

right_click = driver.find_element_by_id ( "") to be positioned to the right-click operation element

ActionChains(driver).context_click(right_click).perform()

  Call ActionChains () class, the browser driver driver as a parameter  

  context_click () method for simulating a mouse right-click operation, you need to specify the elements positioned in the call

  perform () to perform all acts of ActionChains stored, it can be understood as filed actions for the entire operation

 

Hover

above = driver.find_element_by_id ( "") to the positioning element to hover

ActionChains(driver).move_to_element(above).perform()

 

Double-click mouse operation

double_click = driver.find_element_by_id ( "") to the positioning element to hover

ActionChains(driver).double_click(double_click).perform()

 

Drag and drop operation

element = driver.find_element_by_id ( "") the mouse to drag and drop the original target

target = driver.find_element_by_id ( "") to drag and drop to a position

ActionChains(driver).drag_and_drop(element, target).perform()

Guess you like

Origin www.cnblogs.com/97xiaolai/p/11707214.html