Python automated learning - mouse and keyboard events

Import webdriver the Selenium from 
from selenium.webdriver Import ActionChains 
Import Time 

Driver = webdriver.Chrome () 
driver.get ( "https://www.baidu.com/") 

# mouse events 
"" " 
the perform () execution ActionChains class storage all acts 
context_click () Right-click the event 
double_click () Double-click the event 
drag_and_drop () drag event 
move_to_element () mouseover event 
"" " 

above = driver.find_element_by_link_text (" settings ") 
ActionChains (Driver) .move_to_element (above). the perform () 
# driver.find_element_by_link_text ( "advanced Search") .click () 
the time.sleep (2) 

# key events 
from selenium.webdriver.common.keys Import Keys 

# input box contents 
driver.find_element_by_id ( "kw").send_keys("seleniumm") 
the time.sleep (2) 

# delete multiple an input m
driver.find_element_by_id ( "kw"). send_keys (Keys.BACK_SPACE) 
the time.sleep (2) 

# Enter Space + "Tutorial" 
driver.find_element_by_id ( "kw"). send_keys (Keys.SPACE) 
driver.find_element_by_id ( "kw ") .send_keys (" tutorial ") 
the time.sleep (2) 

# enter key combination Ctrl + a Select input box content 
driver.find_element_by_id (" kW "). send_keys (Keys.CONTROL, 'a') 
Time. SLEEP (2) 

# enter key combination Ctrl + x content input box shear 
driver.find_element_by_id ( "kW"). send_keys (Keys.CONTROL, 'X') 
the time.sleep (2) 

# enter key combination Ctrl + v the paste content input box 
driver.find_element_by_id ( "kW"). send_keys (Keys.CONTROL, 'V') 
the time.sleep (2) 

# () instead of the enter key click operation with the click 
driver.find_element_by_id ( "SU") .send_keys (Keys.ENTER)
time.sleep(2)

driver.quit()

  

Guess you like

Origin www.cnblogs.com/LT-XILI/p/11619591.html