导入ActionChains类 from selenium.webdriver.common.action_chains import ActionChains 1.move_to_element(to_element) ——鼠标移动到某个元素 2.context_click(on_element=None) ——点击鼠标右键 3.double_click(on_element=None) ——双击鼠标左键 4.perform():执行所有 ActionChains 中存储的行为
import selenium
import time
from selenium import webdriver
#导入ActionChains类
from selenium.webdriver.common.action_chains import ActionChains
driver = webdriver.Chrome()
driver.get("https://www.baidu.com")
element = driver.find_element_by_link_text('设置')
#鼠标移到元素上面
ActionChains(driver).move_to_element(element).perform()
time.sleep(3)
element = driver.find_element_by_link_text('搜索设置')
#鼠标右击
ActionChains(driver).context_click(element).perform()