# 要想使用鼠标事件,得导入鼠标事件类 from selenium.webdriver.common.action_chains import ActionChains from selenium import webdriver driver = webdriver.Chrome() driver.get("https://www.baidu.com/") # 定位到要悬停的元素 ele = driver.find_element_by_name("tj_briicon") # 对元素进行鼠标悬停的操作,当代码中有鼠标事件的时候,自己就不能动鼠标了 ActionChains(driver).move_to_element(ele).perform() # 右键操作 ActionChains(driver).context_click(ele).perform() # 单击操作 ActionChains(driver).click(ele).perform() # 双击 ActionChains(driver).double_click(ele).perform() # 拖拽, 将元素1 拖动到元素2上面 # ActionChains(driver).drag_and_drop(ele1, ele2).perform()
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。