selenim之常用鼠标击键盘操作

鼠标操作

前提

from selenium.webdriver.common.action_chains import ActionChains#鼠标模块

from selenium.webdriver.commom.keys import Keys#键盘模块

操作名

操作方法

右击

ActionChains(driver).context_click(element).perform()

鼠标悬停

ActionChains(driver).move_to_element(element).perform()

拖曳

ActionChains(driver).drag_and_drop(star_element,end_element).perform()

双击

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

模拟键盘输入

driver.find_element_by_id(id_name).send_keys(keys.BACKSPACE)#后退

driver.find_element_by_id(id_name).send_keys(keys.CONTROL,’a’)#全选

  • Keys.BACK_SPACE:删除键
  • Keys.SPACE:空格键
  • Keys.TAB:Tab键
  • Keys.ESCAPE:回退键
  • Keys.ENTER:回车键
  • Keys.CONTROL,”a”:组合键,Ctrl + A
  • Keys.CONTROL,”x”:组合键,Ctrl + X
  • Keys.CONTROL,”v”:组合键,Ctrl + V
  • Keys.CONTROL,”c”:组合键,Ctrl + C
  • Keys.F1:F1键
  • Keys.F12:F12键

猜你喜欢

转载自blog.csdn.net/qq_35577990/article/details/90138059