# -*- coding:utf-8 -*- ''' @project: web学习 @author: Jimmy @file: 鼠标操作.py @ide: PyCharm Community Edition @time: 2019-01-22 11:15 @blog: https://www.cnblogs.com/gotesting/ ''' from selenium import webdriver from selenium.webdriver.common.action_chains import ActionChains as AC import time driver = webdriver.Chrome() driver.get('http://www.baidu.com') ''' # 鼠标操作 # 由selenium的ActionChains类来完成鼠标操作 # (1)存储鼠标操作 # (2)perform()来执行鼠标操作 # double_click 双击操作 # context_click 右键操作 # drag_and_drop 拖拽操作:左键按住拖动某一个元素到另一个区域,然后释放按键 # move_to_element 鼠标悬停 from selenium.webdriver.common.action_chains import ActionChains as AC # AC.方法名(元素).perform() ''' # 设置按钮 time.sleep(3) ele = driver.find_element_by_xpath('//span[@class="setting-text"]') # 鼠标悬浮在设置上 AC(driver).move_to_element(ele).perform() ''' # 键盘操作 from selenium.webdriver.common.keys import Keys # send_keys(Keys.CONTROL,'a') Ctrl+A # send_keys(Keys.CONTROL,'c') Ctrl+C # send_keys(Keys.CONTROL,'x') Ctrl+X # send_keys(Keys.CONTROL,'v') Ctrl+V # 常用的非组合键 # 回车键 Keys.ENTER # 空格键 Keys.BACK_SPACE # 删除键 Keys.SPACE # 制表符 Keys.TAB # 回退键 Keys.ESCAPE # 刷新键 Keys.F5 '''