Mouse-related operations are encapsulated in a method ActionChains class.
Before use, the need to call ActionChains.
from selenium.webdriver import ActionChains
(1) perform (): perform all acts ActiobChains stored in class
(2) context_click (): Right-click
(3) double_click (): double-click
(4) drag_and_drop (): Drag
(5) move_to_element (): Hover
from Selenium Import the webdriver # introduced ActionChains class from selenium.webdriver Import ActionChains Driver = webdriver.Chrome () driver.get ( " https://www.baidu.com " ) # targeting elements to hover above = driver.find_element_by_link_text ( " settings " ) # of positioning elements to perform mouse hovering operation ActionChains (Driver) . move_to_element (above) .perform ()
running result: