Mouse and keyboard operation

先导入
from selenium.webdriver.common.action_chains import ActionChains


Mouse operation:
After each simulation event to be added .perform () will be performed


1.context_click () Right-click


2.double_click () Double-click on


3.drag_and_drop(source, target) 拖动

source: to drag elements to drag the target location

 


4.move_to_element (element) Hover

Hovering over the element element

 

5.drag_and_drop_by_offset(self, source, xoffset, yoffset)

source: mouse to drag the original element

xoffset: mouse to drag element to another position coordinate x

yoffset: the mouse to drag the element to another location of the y coordinate

 

Operation of the keyboard:

先导入 from selenium.webdriver.common.keys import Keys

 

# Send_keys (Keys.BACK_SPACE) Delete key (BackSpace)


# Send_keys (Keys.SPACE) spacebar (Space)


# Send_keys (Keys.TAB) Tabulator (Tab)


# Send_keys (Keys.ESCAPE) Backspace key (Esc)


# Send_keys (Keys.ENTER) Enter key (Enter)


# send_keys(Keys.CONTROL,'a') 全选(Ctrl+A)


# send_keys(Keys.CONTROL,'c') 复制(Ctrl+C)


# Send_keys (Keys.CONTROL, 'x') Cut (Ctrl + X)


# Send_keys (Keys.CONTROL, 'v') Paste (Ctrl + V)


# Send_keys (Keys.F1) Keyboard F1


# ……


# Send_keys (Keys.F5) keyboard F5


# …


# Send_keys (Keys.F12) keyboard F12


Import the webdriver Selenium from
# Import module Keys
from selenium.webdriver.common.keys Keys Import
Driver = webdriver.Firefox ()
driver.get ( "http://www.baidu.com")
# input box content
driver.find_element_by_id ( "kw"). send_keys ( "seleniumm")
# Backspace key (to delete the contents of the input)
driver.find_element_by_id ( 'kw'). send_keys (Keys.BACK_SPACE)
# as the keyboard F5 to refresh the
driver.find_element_by_id ( 'kw'). send_keys (Keys.F5)
# input space + "tutorial"
driver.find_element_by_id ( "kw"). send_keys (Keys.SPACE)
driver.find_element_by_id ( "kw"). send_keys (U 'tutorial')
# Ctrl + A full selected from the content input box
driver.find_element_by_id ( "kW"). send_keys (Keys.CONTROL, 'A')
# Ctrl + X shear content input box
driver.find_element_by_id("kw").send_keys(Keys.CONTROL, 'x')
# Ctrl + v paste inside the input box
driver.find_element_by_id ( "kw"). Send_keys (Keys.CONTROL, 'v')

 

Guess you like

Origin www.cnblogs.com/wulinmiao/p/11491763.html